【发布时间】:2014-09-16 17:29:49
【问题描述】:
我正在尝试使用 jquery ajax 将 json 数组传递给我的代码。
什么有效:
如果我使用带有空 json 字符串 ("{}") 的 jQuery .ajax() 调用我的代码隐藏函数,我的代码隐藏函数将毫无问题地触发。
我想做的事:
如果我将一个 Json 字符串放到 jQuery .ajax() 的“数据”属性中,然后使用字符串参数创建一个代码隐藏函数,它就不会再被触发。
这是我的代码:
客户端
function SendAjax() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/MyFunction",
data: '{"foo":"bar"}',
dataType: "json",
success: function (msg) {
//DO Somtething
},
error: function (xhr, status, error) {
//DO Somtething
}
});
}
服务器端
[WebMethod]
public static string MyFunction(string jsonData)
{
//Do something
return "test";
}
- 我的 json 数组格式正确
- 我有一个静态函数
- 我有
[WebMethod]
我错过了什么吗?
【问题讨论】: