this is my client side ajax call:
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..."); }
});
this is chrome network header:
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
Form Dataview URL encoded
data:a
data:b
data:c
data:d
this is my webapi controller method:
public HttpResponseMessage UpdateStatusToDelete(string[] data)
result:
when I debug, the data parameter in UpdateStatusToDelete returns {string[0]}
instead of data:a
data:b
data:c
data:d
What am I doing wrong? Any help is really appreciated.
list
variable as the data field in your ajax call. Right now, it looks like you are passing an object which has an array of strings as a member field called "data". – Ameen Jan 8 '13 at 5:51string[] list = {"a", "b", "c", "d"};
– DJ KRAZE Jan 8 '13 at 5:52