【发布时间】:2011-09-28 02:57:31
【问题描述】:
我很困惑为什么会这样。
我似乎无法通过$.ajax 成功传递数据,URL 被全部弄乱了,而不是在查询字符串中传递数据。
为了简洁起见,我已经清理了代码,见下文。
网络服务(使用 GET)
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string TestMethod(string country, string city)
{
return country + city;
}
jQuery
$.ajax({
url: "Test.asmx/TestMethod",
type: "GET",
data: '{"country":"' + country + '","city":"' + city + '"}',
dataType: "json",
success: function(msg) {
alert(msg.d);
}
});
生成的 URL 和错误(在 Firebug 中)
http://example.com/Test.asmx/TestMethod?{%22country%22:%22NZ%22,%22city%22:%22AK%22}
System.InvalidOperationException: Missing parameter: country.
【问题讨论】:
标签: c# ajax web-services jquery