即使一切正常,ajax也会返回错误

时间:2018-10-18 09:48:38

标签: javascript ajax post

我有这个简单的代码

数据定期保存在服务器上,但始终会生成错误“ Error ListaSegnalazioni!undefined”

如果我删除指令e.preventDefault();,该错误将消失!

可能是什么问题?

    e.preventDefault();
    $.ajax({
          type: "POST",
          url: '/api/PostListaSegnalazioni/',
          data: JSON.stringify(rows),
          "dataSrc": "",
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(data) {
            alert("Dati Inviati!");
          },
            error: function(xhr, status, error) {
              alert("Error ListaSegnalazioni! " + xhr.responseText);
            }
          });

1 个答案:

答案 0 :(得分:0)

***不可思议!! *****

我修改了代码,错误消失了!

$.ajax({
                                type: "POST",
                                url: '/api/PostListaSegnalazioni/',
                                data: JSON.stringify(rows),
                                "dataSrc": "",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function (data) {
                                    alert("Dati Inviati!");
                                },
                                error: function (xhr, status, error) {
                                    alert(xhr.responseText.includes("undefined"));
                                 if (xhr.responseText != "undefined") { alert("Error ListaSegnalazioni! " + xhr.responseText);}
                                }
                            });

插入指令alert(xhr.responseText.includes("undefined"));

就足够了

非常非常奇怪的行为!