json解析错误意外结束数据。 [英] json parse error unexpected end of data.
本文介绍了json解析错误意外结束数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些通过json传递id的功能。但它返回错误以下
JSON.parse:意外结束数据
i不知道为什么不在生产服务器上工作。在我当地的机器上工作正常。这是我的代码。
Hi,
i have some functionality to pass id via json. but it returns below error
JSON.parse: unexpected end of data
i have no idea why not working on production server. works fine on my local mahchine. here is my code.
function AddSubscriptionToList(PublicationID, EmployeeID) {
var pubid = { "PublicationID": PublicationID, "EmployeeID": EmployeeID };
$.ajax({
url: '@Url.Action("AddSubscriptionToDB", "Home")',
cache: false,
type: 'POST',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(pubid),
success: function (data) {
//alert('added');
loadPublicationList();
}
}).fail(
function (xhr, textStatus, err) {
alert(err);
});
}
推荐答案
.ajax({
url:'@ Url.Action(AddSubscriptionToDB, Home)',
cache:false,
type:'POST',
dataType:'json',
contentType:'application / json; charset = utf-8' ,
数据:JSON.stringify(pubid),
成功:函数(数据){
// alert('added');
loadPublicationList();
}
})。失败(
函数(xhr,textStatus,错误){
alert(err);
});
}
.ajax({ url: '@Url.Action("AddSubscriptionToDB", "Home")', cache: false, type: 'POST', dataType: 'json', contentType: 'application/json; charset=utf-8', data: JSON.stringify(pubid), success: function (data) { //alert('added'); loadPublicationList(); } }).fail( function (xhr, textStatus, err) { alert(err); }); }
应该更像这样
Should be more like this
function AddSubscriptionToList(PublicationID, EmployeeID) {
var pubid = { "PublicationID": PublicationID, "EmployeeID": EmployeeID };
.ajax({
url:'@ Url。 Action(AddSubscriptionToDB,Home)',
cache:false,
type:'POST',
dataType:'json',
contentType:'application / json ; charset = utf-8',
数据:JSON.stringify(pubid),
错误:函数(xhr,状态,错误){
alert(xhr.responseText);
},
成功:函数(数据){
// alert('added');
loadPublicationList();
}
});
}
.ajax({ url: '@Url.Action("AddSubscriptionToDB", "Home")', cache: false, type: 'POST', dataType: 'json', contentType: 'application/json; charset=utf-8', data: JSON.stringify(pubid), error: function (xhr, status, error) { alert(xhr.responseText); }, success: function (data) { //alert('added'); loadPublicationList(); } }); }
这篇关于json解析错误意外结束数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文