我有以下腳本:與對象列表AJAX調用
obj = [];
obj = [{ AllocationStatus: false,
BRId: 2,
BRName: "rifat",
SupervisorId: 19,
SupervisorName: "Ashraful"
}];
console.log(obj);
var data2send = JSON.stringify(obj);
$.ajax({
type: "POST",
url: "../WebService1.asmx/allocatebr",
data: "{'brlist':'" + data2send + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
},
error: function() {
alert('error f');
}
});
在Web服務
我有以下代碼:
[WebMethod]
public string allocatebr(List<Allocation> brlist)
{
//foreach(Allocation br in brlist){
//}
return "success";
}
public class Allocation
{
public int SupervisorId { get; set; }
public string SupervisorName { get; set; }
public int BRId { get; set; }
public string BRName { get; set; }
public bool AllocationStatus { get; set; }
}
,但我得到的錯誤:無法加載資源:服務器迴應的狀態是500(內部服務器錯誤)。我的代碼出了什麼問題?我想將對象列表傳遞給method.how來完成它?任何人都可以幫助我,非常感謝。 n.b.i得到obj的陣列
`$('.chkgrip').each(function() {
if ($(this).is(':checked')) {
var x = $(this).closest('tr').data('row');
obj.push(x);
}
});`
對於這樣的地方,你真的不知道的問題,如果問題出在客戶端或服務器端,你會做得很好使用類似[提琴手] (http://fiddler2.com/)來讀取您正在做的HTTP請求,並查看請求的正文是否與您希望的一樣。 在你的情況看來,客戶端代碼工作得很好,請求的正文包含了你所期望的json blob。 你需要找出內部服務器錯誤,才能真正幫助你 –
plz sugest一些tutorial.i不能得到它 – decoder