加载ajax响应时,jQuery执行函数 [英] jquery execute function while ajax response is loading
本文介绍了加载ajax响应时,jQuery执行函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何执行将在客户端等待服务器响应时运行的功能?这是我的代码.我抬起头,发现一个.load()函数,但是它如何适合呢?任何帮助将是巨大的!谢谢
How can I execute a function that will run while the client is waiting for the server response? Here is my code. I looked up and found a .load() function, but how does that fit into this? Any help would be great! Thanks
$.ajax({
type: "POST",
url: "mail.php",
data: {name: name.val(), email: email.val(), phone: phone.val(), subject: subject.val(), message: message.val()}
}).done(function(){
alert("Your message was sent. We will be in contact with you shortly.");
window.location="index.html";
});
推荐答案
您编写的下一行代码 您调用$ .ajax()将在浏览器等待响应时运行.
The very next line of code you write after You call $.ajax() will run while the browser is waiting for a response.
所以:
$.ajax();
yourAwesomeFN();
XhttpRequest是异步的.无需额外的工作.
XhttpRequests are asynchronous. No extra work required.
这篇关于加载ajax响应时,jQuery执行函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文