javascript - Having Trouble with a cross Domain jquery/Ajax service call -
i've read through thread after thread on here , elsewhere trying cross domain ajax call work. have restful wcf service returns simple bool. have setup proper response format (json) , expected url callback parameter:
[webget(requestformat = webmessageformat.json, responseformat = webmessageformat.json, uritemplate = "showcreditcardtextjquery?membernumber={membernumber}&callback={callback}", bodystyle = webmessagebodystyle.wrappedrequest)]
my ajax looks this:
$.ajax({ url: "http://example.com/service/service.svc/showtextjquery", type: "get", contenttype: "application/json; charset=utf-8", datatype: "jsonp", crossdomain:true, data: "{'membernumber':'" + membernumber + "'}", cache: false, //success: alert(membernumber), success: function (data) { var output = data; if (!data) { $("#dialog").dialog( { modal: true, width: 735, height: 550 }); } }, error: function (xhr, ajaxoptions, thrownerror) { alert(xhr.status); } });
i receive 200 response coming in error block. @ loss (and still pretty new jquery/ajax). appreciated.
may these lines of code solve problem, regular web service call
var jsondata = [your json parameter]; $.ajax({ async: false, type: "post", url: [your web service url], contenttype: "application/json; charset=utf-8", data: json.stringify({ json: jsondata }), datatype: "json", success: onsuccess, failure: function(err) { alert("error : " + err.d); } }); function onsuccess(data) { alert("success:" + data.d); }
you can 1 thing need set access-control-allow-origin & access-control-allow-headers in customeheaders web service web.config file.
<add name="access-control-allow-origin" value="*" /> <add name="access-control-allow-headers" value="content-type" />
if want allow specific domain , can specific value of domain instead of * value
Comments
Post a Comment