我希望将一个对象传递给控制器并检索控制器中的值。我的定义如下:
Html代码:
var positionarray = [];Javascript:
$("#button").live('click',function(){
positionarray.push({
id: sessionStorage.getItem('id'),
value: $("#input").val()
});
});
// on save button click
$.ajax({
type: "GET",
url:"/Bugs/Position",
data: {
array:positionarray
},
cache: false,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (json) {
}
});但是我无法检索控制器中的值。它正在变为null。
发布于 2013-04-29 13:18:25
试试这个:
你的ajax call必须在按钮点击功能中,然后它才能工作,
在您的代码中,ajax call在单击之前运行,因此它会将空传递给控制器
$("#button").live('click',function(){
positionarray.push({
id: sessionStorage.getItem('id'),
value: $("#input").val()
});
// on save button click
// this code must run after `button click` and after pushing data in
// positionarray variable
$.ajax({
type: "GET",
url:"/Bugs/Position",
data: {
array:positionarray
},
cache: false,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (json) {
}
});// here ajax function code ends
});// here button click function endshttps://stackoverflow.com/questions/16271404
复制相似问题