【发布时间】:2014-05-05 01:57:15
【问题描述】:
我在使用 ajax 将数据发布到控制器时遇到问题,我试图通过 ajax 将字符串发送到控制器但它甚至没有到达控制器,我的代码是这样的:
var m_page_nm = $('#pagemenu_hid').val(),
oColumns = JSON.stringify(this.oKgrid.columns),
data = JSON.stringify({ columns: oColumns, page_name: m_page_nm, grid_nm: this.m_kgrid_id });
$.ajax({
url: "/Favorite/SaveColumnSettings",
type: 'POST',
data:{ gridset:data },
dataType: 'json',
contentType: 'application/json; charset=utf-8',
error: function (xhr) {
alert('Error: ' + xhr.statusText);
},
});
在控制器中就这么简单
[HttpPost]
public ActionResult SaveColumnSettings(string gridset)
{
return new EmptyResult();
}
在开发者工具上是这个请求
Request URL:http://localhost:2144/Favorite/SaveColumnSettings
Request Headers CAUTION: Provisional headers are shown.
Accept:*/*
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Origin:http://localhost:2144
Referer:http://localhost:2144/Agent/Index?menu=AGENT_SETUP
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
gridset:{"columns":" [{\"encoded\":true,\"title\":\"Id\",\"hidden\":true,\"field\":\"agent_no\",\"filterable\":{},\"attributes\":{\"style\":\"display:none\"},\"footerAttributes\":{\"style\":\"display:none\"},\"headerAttributes\":{\"style\":\"display:none\"}},{\"encoded\":true,\"title\":\"Agent Code\",\"width\":\"20px\",\"field\":\"agent_cd\",\"groupable\":false,\"filterable\":{}},{\"encoded\":true,\"title\":\"Agent Name\",\"width\":\"80px\",\"field\":\"agent_nm\",\"groupable\":false,\"filterable\":{}},{\"encoded\":true,\"title\":\"Supervisory Code\",\"width\":\"20px\",\"field\":\"supervisor_cd\",\"filterable\":{}},{\"encoded\":true,\"title\":\"Sales Dept. Code\",\"width\":\"20px\",\"field\":\"sdept_cd\",\"filterable\":{}},{\"encoded\":true,\"title\":\"Area\",\"width\":\"20px\",\"field\":\"area_cd\",\"filterable\":{}},{\"encoded\":true,\"title\":\"Active?\",\"width\":\"10px\",\"template\":\"<div style='text-align:center'><input type='checkbox' disabled checked #= inactive_yn? checked='checked': checked='' # class='chkbx' /></div>\",\"field\":\"inactive_yn\",\"filterable\":{}}]","page_name":"AGENT_SETUP","grid_nm":"#agent_kgrid"}
【问题讨论】:
-
有什么错误吗?或者使用google chrome developer tools(f12)或者firefox firebugs来检查url是否正确
-
我在开发者工具上没有任何错误。我的问题是,即使 url 正确,它也无法到达我的控制器,当它到达控制器时,参数为空......我已经储存了几天
-
@Se0ng11 我有上面的编辑...我已经发送了那个请求,但它没有到达我的控制器
-
我看到你的json无效,尝试使用jsoneditoronline.org/index.html之类的工具来检查你的json是否正确,我只能提供帮助
-
@Se0ng11 该网站说我有 3 个对象,这意味着我的 json 是正确的..???列是一个字符串,然后是 page_nm 和 grid_nm
标签: c# jquery ajax asp.net-ajax