Jquery WebService请求格式无效
WebSercie中代码
C# code
[WebMethod]
public ArrayList HelloWorld()
{
ArrayList al = new ArrayList(200);
for (int i = 0; i < 10; i++)
{
ArrayList alItem = new ArrayList();
alItem.Add(i);
alItem.Add(i+"ab");
al.Add(alItem);
}
return al;
}
JS代码
JScript code
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/WebService/ProductGroupService.asmx/HelloWorld",
data: "{}",
success: function(data) {
alert("Success");
},
error: function(err) {
alert(err.responseText);
}
});
这个该怎么改
提示请求格式无效:application/json; charset=utf-8
在线等
------解决方案--------------------public ArrayList HelloWorld()
{
ArrayList al = new ArrayList(200);
for (int i = 0; i < 10; i++)
{
ArrayList alItem = new ArrayList();
alItem.Add(i);
alItem.Add(i+"ab");
al.Add(alItem);
}
//return al;
Response.Write("{\"key1\":\"value\",\"key2\":\"value\"}");
}
这个是最简单的json的格式,楼主试试,前台能获取 data 吗
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/WebService/ProductGroupService.asmx/HelloWorld",
data: "{}",
success: function(data) {
alert(data);
},
error: function(err) {
alert(err.responseText);
}
});
------解决方案--------------------ArrayList是后台的变量类型,返回到前台,js又不能识别
需要返回js能识别的变量类型
------解决方案--------------------
返回的格式不对