$.ajax({
url: "test.html",
context: document.body
}).done(function() {
//show data
});
如何将数据从ajax请求保存到变量中,然后显示它? 以及如何在处理过程中显示消息“loading ...”?如何将ajax调用请求数据保存在变量中并显示它?
$.ajax({
url: "test.html",
context: document.body
}).done(function() {
//show data
});
如何将数据从ajax请求保存到变量中,然后显示它? 以及如何在处理过程中显示消息“loading ...”?如何将ajax调用请求数据保存在变量中并显示它?
$.ajax({
url: "test.html",
context: document.body
}).done(function(data) {
alert(data);
});
更新:
$.ajax({
url: "test.html",
context: document.body
}).done(function(data) {
$('#loading').hide();
// alert(data);
});
标记:
<div id='loading'></div>
可能的重复感谢如何在请求发送时显示“加载...”消息? –
加载消息,在AJAX使用beforeSend()。
beforeSend : function() {
$('body').html('Loading...');
}
你可以尝试这样的事情。在你的函数可以显示加载DIV
function your_ajax() {
$('#loading').show();
$.ajax({
url: "test.html",
context: document.body
}).done(function(data) {
$('#loading').hide();
alert(data);
});
}
请在你的HTML添加此部分
<div id="loading" style="display:none;">Loading </div>
谢谢@Shafeeq –
如何在超时请求中包装这个例子,例如每5秒刷新一次? –
功能(数据){...}); ?? – MightyPork
http://stackoverflow.com/questions/905298/jquery-storing-ajax-response-into-global-variable –