jquery - JSON Parse Error Garble -


i trying call asmx webservice client code using jquery. i'm finding difficult achieve this. can help?

what happening:

  1. jsonconvert library use made newtonsoft convert object json returning.

  2. the asmx being hosted on domain b.company.com

  3. the client ajax call hosted on domain a.compay.com

  4. fiddler picking single call two(2) 401 200 not viewable in json tab of reply.

this asmx code:

[webmethod]     [scriptmethod(responseformat = responseformat.json)]     public string pingcrm()     {         try         {             return jsonconvert.serializeobject(new             {                 status = "ok",                 data = "hello crm"             });         }         catch (exception ex)         {             return jsonconvert.serializeobject(new             {                 status = "error",                 data = ex             });         }     } 

this ajax jquery code:

$.ajax({             url: url,             type: "post",             data: {},             contenttype: "application/json; charset=utf-8",             datatype: 'json',             success: function (result) {                 console.log('ajax success');                  console.log('result = [' + result + ']');             },             error: function (xhr, status, error) {                 var txterror = 'status = [' + status + ']; respsonse = [' + xhr.responsetext + ']; respsonse = [' + error + ']';                 console.log(txterror);             }         }); 

this fiddler "raw" view of response:

http/1.1 200 ok cache-control: private, max-age=0 content-type: text/xml; charset=utf-8 vary: accept-encoding server: microsoft-iis/7.5 x-aspnet-version: 4.0.30319 persistent-auth: true x-ua-compatible: ie=9 access-control-allow-origin: * access-control-allow-headers: content-type, accept access-control-allow-methods: get, post www-authenticate: negotiate orswgaadcgeaoxieeaeaaacwch0ugarqcwaaaaa= date: thu, 15 aug 2013 22:47:12 gmt content-length: 127 <?xml version="1.0" encoding="utf-8"?> <string xmlns="http://b.company.com/">{"status":"ok","data":"hello crm"}</string> 

the response compressed (see response header: content-encoding: gzip). fiddler should able decompress you, clicking bar on top of response (see below). if don't see that, try upgrading newer version of fiddler.

fiddler response gzip encoding

edit after update in question: problem have response not in json format, xml (with json inside xml document), $.ajax won't able parse in result parameter. can either try change server return json instead of xml, or can response text jqxhr object passed third argument success function, extract json xml , parse result yourself.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -