使用异步jQuery的时候没有得到答复 [英] jQuery not getting reply when using asynchronous
问题描述
我用这code得到响应从服务器返回。但我想异步,因为我需要显示进度。当我用这个code,我没有得到任何一封邮件从服务器返回(只获得警觉对象)。这里是我的code。任何想法?
VAR味精= $阿贾克斯({
输入:POST,
网址:'../pages/registration.php',
异步:真实,
数据:{
这样做:注册
},
beforeSend:功能(){
$(#进步)显示()。
},
成功:功能(数据,状态){
$(#进展),隐藏()。
$(#AckMsg)的html(数据)。
}
});
警报(AA+味精);
在jQuery 1.5中,XMLHtt prequest(jqXHR)对象由$。阿贾克斯()返回。这是分配给您的VAR味精的对象,后来放在警报。因此,你得到警报为目标为你描述它。如果你想提醒什么是服务器返回,这样做:
成功:功能(数据,状态){
$(#进展),隐藏()。
$(#AckMsg)的html(数据)。
警报(数据);
}
如果这个警报数据,空或未定义。检查你的Ajax调用的网址。
网址:'../pages/registration.php',
我相信使用这样的相对URL会做出Ajax请求的http:/ /www.yoursite.com/../pages/registration.php 为例。这很可能是你想要做什么。
I am using this code to get response back from server. But I want that asynchronously as I need to show progress. When I use this code, I don't get any messsage back from server (only getting alert as object). Here is my code. Any ideas?
var msg = $.ajax({
type: 'POST',
url: '../pages/registration.php',
async: true,
data: {
do: 'register'
},
beforeSend: function () {
$("#Progress").show();
},
success: function (data, status) {
$("#Progress").hide();
$("#AckMsg").html(data);
}
});
alert("aa" + msg);
As of jQuery 1.5, a XMLHttpRequest (jqXHR) object is returned by $.ajax(). This is the object you assign to your var msg, and later put in the alert. Hence you get "alert as object" as you describe it. If you want to alert what is returned by the server, do:
success: function (data, status) {
$("#Progress").hide();
$("#AckMsg").html(data);
alert(data);
}
If this alerts data as empty or undefined. Check your ajax call URL.
url: '../pages/registration.php',
I believe using a relative URL like this will make a ajax request to http://www.yoursite.com/../pages/registration.php for example. This is most likely not what you want to do.
这篇关于使用异步jQuery的时候没有得到答复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!