这是我的客户端 ajax 调用:
var list = ["a", "b", "c", "d"];
var jsonText = { data: list };
$.ajax({
type: "POST",
url: "/api/scheduledItemPriceStatus/updateStatusToDelete",
data: jsonText,
dataType: "json",
traditional: true,
success: function() { alert("it worked!"); },
failure: function() { alert("not working..."); }
});
这是 chrome 网络标头:
Request URL:http://localhost:2538/api/scheduledItemPriceStatus/updateStatusToDelete
Request Method:POST
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:27
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:localhost:2538
Origin:http://localhost:2538
Referer:http://localhost:2538/Pricing/ScheduledItemPrices
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11
X-Requested-With:XMLHttpRequest
表单 Dataview URL 编码
data:a
data:b
data:c
data:d
这是我的 webapi 控制器方法:
public HttpResponseMessage UpdateStatusToDelete(string[] data)
结果:
当我调试时,UpdateStatusToDelete 中的 data 参数返回{string[0]}
而不是 data:a data:b data:c data:d
我究竟做错了什么?非常感谢任何帮助。