以下代码从文件加载html内容(我使用此线程)
<script>
$.fn.loadWithoutCache = function (){
$.ajax({
url: arguments[0],
cache: false,
dataType: "html",
success: function(data) {
$(this).html(data); // This is not working
//$('#result').html(data); //THIS WORKS!!!
alert(data); // This alerts the contents of page.html
}
});
}
$('#result').loadWithoutCache('page.html');
</script>
Run Code Online (Sandbox Code Playgroud)
请告诉我这是什么问题?我希望这是一个愚蠢的东西:)
编辑:正确的代码
<script>
$(document).ready(function() {
$.fn.loadWithoutCache = function (){
var $el = $(this);
$.ajax({
url: arguments[0],
cache: false,
dataType: "html",
context: this,
success: function(data) {
$el.html(data);
}
});
}
$('#result').loadWithoutCache('page.html');
});
</scipt>
Run Code Online (Sandbox Code Playgroud)
谢谢乔恩和大家!