小编典典

数据插入成功,但jQuery仍返回错误

ajax

我使用以下jQuery通过数据服务插入数据。事件虽然我得到了状态响应201,并且数据已成功插入到我的数据库中,但系统仍然将其视为错误并给我“失败”警报?

我在这里想念什么?

$.ajax({
    type: "POST",
    url: "http://localhost:49223/Form/WebDataService.svc/XMLForm(guid'1eaef3a0-d6df-45bf-a8f6-3e7292c0d77e')/XMLRecord/",
    data: JSON.stringify(record),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function() {
        alert("Success");
    },
    error: function(xhr) {
        alert("fail");
    }
});

更新:

来自Fire Bug的调试消息:

Preferences

POST http://localhost:49223/Form/WebDataService.svc/X...ef3a0-d6df-45bf-a8f6-3e7292c0d77e%27)/XMLRecord/

POST http://localhost:49223/Form/WebDataService.svc/XMLForm(guid%271eaef3a0-d6df-45bf-a8f6-3e7292c0d77e%27)/XMLRecord/

jquery....min.js (line 127)
POST http://localhost:49223/Form/WebDataService.svc/X...ef3a0-d6df-45bf-a8f6-3e7292c0d77e%27)/XMLRecord/

POST http://localhost:49223/Form/WebDataService.svc/XMLForm(guid%271eaef3a0-d6df-45bf-a8f6-3e7292c0d77e%27)/XMLRecord/

201 Created 6.7s

POST http://localhost:49223/Form/WebDataService.svc/X...ef3a0-d6df-45bf-a8f6-3e7292c0d77e%27)/XMLRecord/

POST http://localhost:49223/Form/WebDataService.svc/XMLForm(guid%271eaef3a0-d6df-45bf-a8f6-3e7292c0d77e%27)/XMLRecord/

201 Created


get readyState 4

get responseText "{ "d" : {\r\n"__metadata"...\')/XMLForm"\r\n}\r\n}\r\n} }"

get responseXML null

get status 201

get statusText "Created"

阅读 183

收藏
2020-07-26

共1个答案

小编典典

您必须发送{dataType:’text’}才能使成功函数与jQuery和空响应一起使用。

2020-07-26