Skip to content

Commit

Permalink
fix text load cache for util/ajax/loader/text
Browse files Browse the repository at this point in the history
  • Loading branch information
caijf committed Oct 25, 2017
1 parent 3fe9605 commit c557938
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
--------------------------------------------------------
- BUG修复模块
* base/util 模块的 _$url2origin 接口支持相对协议
* util/ajax/loader/text 修正 XHR 重复加载文本内容时被缓存问题

0.4.5 (2017-09-14)
--------------------------------------------------------
Expand Down
34 changes: 22 additions & 12 deletions src/util/ajax/demo/tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
<head>
<title>test tag</title>
<meta charset="utf-8"/>
<script>
function log(m) {
var p = document.createElement('p');
p.innerHTML = m;
document.body.appendChild(p);
}


</script>
</head>
<body>

<input type="button" value="加载" onclick="a();"/>
<script src="../../../define.js"></script>
<script>
define([
Expand All @@ -14,25 +23,26 @@

_j._$loadTemplate('./b.html',{
onload:function(result){
console.log('same domain');
console.log(result);
log('same domain');
log(result);
}
});

_j._$loadTemplate('http://localhost:8080/nej/src/util/ajax/demo/b.html',{
onload: function(result){
console.log('same domain');
console.log(result);
log('same domain');
log(result);
}
});

_j._$loadTemplate('http://a.b.com:8080/nej/src/util/ajax/demo/b.html',{
onload: function(result){
console.log('cross domain');
console.log(result);
}
});

window.a = function (){
_j._$loadTemplate('http://a.b.com:8080/nej/src/util/ajax/demo/b.html',{
onload: function(result){
log('cross domain');
log(result);
}
});
};
});
</script>
</body>
Expand Down
11 changes: 11 additions & 0 deletions src/util/ajax/loader/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ NEJ.define([
this.__doRequest();
return null;
};
/**
* 执行清理任务
*
* @protected
* @method module:util/ajax/loader/style._$$LoaderText#__doClear
* @return {Void}
*/
_pro.__doClear = function(){
this.__super();
this.__getLoadData('loaded')[this.__url] = !1;
};
/**
* 资源载入
*
Expand Down
4 changes: 3 additions & 1 deletion src/util/ajax/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ NEJ.define([
}else{
var callback = _options.onload;
_options.onload = function(event){
callback(e._$html2node(event.content));
if (!!event){
callback(e._$html2node(event.content));
}
};
_p._$loadText(_url, _options);
}
Expand Down

0 comments on commit c557938

Please sign in to comment.