D.J*_*D.J 19 ajax jquery wcf-data-services
我使用以下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");
}
});
Run Code Online (Sandbox Code Playgroud)
更新:
来自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"
Run Code Online (Sandbox Code Playgroud)
Rub*_*olk 61
您必须发送{dataType:'text'}才能使成功函数与jQuery和空响应一起使用.
D.J*_*D.J 11
解:
即使我仍然无法解决我如何从以前的代码中获得错误,我得到了这个替代解决方案,对我有用.(至少现在(是).
我很想听到更多的想法
谢谢你们
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "http://localhost:49223/Form/WebDataService.svc/XMLForm(guid'1eaef3a0-d6df-45bf-a8f6-3e7292c0d77e')/XMLRecord/",
data: JSON.stringify(record),
complete: function(xhr) {
if (xhr.readyState == 4) {
if (xhr.status == 201) {
alert("Created");
}
} else {
alert("NoGood");
}
}
//
// success: function(data) {
// alert("Success");
// },
// error: function(xhr) {
// alert("fail" + xhr);
// }
});
Run Code Online (Sandbox Code Playgroud)