[英]jQuery success POST php not activate
I'm racking my brain and I can not make it work. 我正在绞尽脑汁,但无法使其正常工作。
I am using jQuery to call a PHP page: 我正在使用jQuery来调用PHP页面:
$.ajax({
type: "POST",
url: postUrl,
data: formData,
async : false,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: App.successfulAdd,
error: App.errorAdd
});
successfulAdd : function(result) {
alert("Success!");
},
The PHP: PHP:
echo json_encode(array('msg' => 'failed'));
Firebug show: 萤火虫展示:
{"msg":"failed"}
But the successfulAdd function is not called! 但是成功调用函数没有被调用! Any idea why?
知道为什么吗?
I have changed to 我已更改为
$.ajax({
type: "POST",
url: postUrl,
data: formData,
async : false,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (data) {
alert("Success!");
},
error: function (data) {
alert("Error!");
}
});
But still Error! 但是还是错误! is displayed.
被陈列。
Update 更新资料
Finally I found! 终于我找到了! Use Notepad++ and was as UTF8 encoding.
使用Notepad ++,并作为UTF8编码。 Changed to UTF8 without BOM and now everything works beautifully.
更改为不带BOM的UTF8,现在一切正常。
Try changing to: 尝试更改为:
success: function(result) {
App.successfulAdd(result);
},
error: function(result) {
App.errorAdd(result);
}
This will evaluate the properties when the response arrives, not when you send the request. 这将在响应到达时(而不是在发送请求时)评估属性。 I suspect you're sending the request while you're building the
App
object, and these properties haven't been assigned yet. 我怀疑您在构建
App
对象时正在发送请求,而这些属性尚未分配。
I think I found the cause of the problem: the version of jQuery. 我想我找到了问题的原因:jQuery版本。
The versions: 1.11.1, 1.11.0, 1.10.2, 1.10.1, 1.10.0, 1.9.1, 1.9.0 not working. 版本:1.11.1、1.11.0、1.10.2、1.10.1、1.10.0、1.9.1、1.9.0不起作用。 The version 1.8.3 works.
版本1.8.3可以使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.