Javascript jQuery成功后php未激活

Javascript jQuery成功后php未激活,javascript,php,jquery,json,Javascript,Php,Jquery,Json,我在绞尽脑汁,不能让它工作 我正在使用jQuery调用PHP页面: $.ajax({ type: "POST", url: postUrl, data: formData, async : false, contentType: 'application/json; charset=utf-8', dataType: 'json', success: App.successfulAdd, error:

我在绞尽脑汁,不能让它工作

我正在使用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!");
},
PHP:

echo json_encode(array('msg' => 'failed'));
萤火虫表演:

{"msg":"failed"}
但是没有调用successfulAdd函数!知道为什么吗


我改成

$.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!");
        }
    });
但仍然是错误!显示

更新

终于找到了! 使用记事本++和was作为UTF8编码。更改为不带BOM的UTF8,现在一切都运行良好。

尝试更改为:

success: function(result) {
    App.successfulAdd(result);
},
error: function(result) {
    App.errorAdd(result);
}

这将在响应到达时评估属性,而不是在发送请求时。我怀疑您在构建
应用程序
对象时发送了请求,但这些属性尚未分配。

我想我找到了问题的原因:jQuery的版本

版本:1.11.1、1.11.0、1.10.2、1.10.1、1.10.0、1.9.1、1.9.0不工作。
版本1.8.3可以工作。

在控制台中查看-请求的状态是什么?我认为您遗漏了一些重要的代码部分
successfulAdd:
肯定存在于某个对象中,它在哪里?看起来您在分配
App.successfulAdd
之前正在进行AJAX调用,因此此时它没有值。请显示全部代码。@tymeJV我想状态是200。是吗?放
console.log(App.successfuldad)
$.ajax
之前,我想您会发现我是对的。在jQuery版本之间,您发布的代码中没有明显的变化。听起来您的代码中有一个旧版本无法检测到的问题,但新版本增加了更多检查。