ajax - POSTing JSON data to WCF Rest Service -
i know there many questions on none of suggestions have worked me.
here code:
var restservice = "http://wcfrestservice:8004/radpocservice/webapp1"; $.ajax({ url: restservice, type: "post", data: { phonenumber: y }, datatype: "json", contenttype: "application/json; charset=utf-8", success: function (data) { window.open(data.url, '_blank'); } });
fiddler shows request going across wire (redacted):
post http://localhost:8004/radpocservice/webapp1 http/1.1 host: localhost:8004 connection: keep-alive content-length: 22 accept: application/json, text/javascript; q=0.01 origin: http://localhost:8000 user-agent: mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/51.0.2704.103 safari/537.36 content-type: application/json; charset=utf-8 referer: http://localhost:8000/default.aspx accept-encoding: gzip, deflate accept-language: en-us,en;q=0.8 requestor: me phonenumber=1234567890
i expecting payload this:
{ "phonenumber": "1234567890"}
when set payload above in fiddler composer tab service works expected. doing wrong?
i hate after posting question answer use json.stringify api on data being sent service. above should have following code 'data' in ajax call:data: json.stringify({ phonenumber: y })
Comments
Post a Comment