用jQuery.ajax加载页面,怎么回事? [英] load a page with jQuery.ajax, how is it?
本文介绍了用jQuery.ajax加载页面,怎么回事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么在单击此代码后不显示(或不加载)mysite.html?
why in this code after click not displaying(or not load) mysite.html?
$('#icon a').click(function (event) {
event.preventDefault();
$('.table_show, #num_count, #select_box, #input_search').fadeOut('slow', function () {
$.ajax({
url: url,
cache: false,
success: function(html){
$(".results").append(html);
$(this).hide().show();
//$.getScript("http://localhost/Siran-mehdi/files/js/admin.js");
}
});
//.hide().show("slow")
});
});
推荐答案
$(".results").load('mysite.html');
当然mysite.html
必须与脚本位于同一文件夹中,否则您可以使用完整的url(始终限于相同的原始策略)'
Of course mysite.html
must be in the same folder as the script, or you can use full url (always restricted to same origin policy) 'http://www.yoursite.com/mysite.html'
您也可以使用 .ajax 方法进行操作, .load 方法只是使其变得简单.
You can also do it with .ajax method, the .load way just make it simple.
$.ajax({
url: "mysite.html", //or full url http://...
success: function(data){
$('.results').html(data);
}
});
在.load
方法中,您也可以设置回调函数:
In .load
method you can set a callback function too:
$(".results").load('mysite.html', myCallback);
您应该查看 jQuery API , http://api .jquery.com/jQuery.ajax/
这篇关于用jQuery.ajax加载页面,怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文