JSON Parse Error Garble
I am trying to call a asmx webservice from client code using jquery.
However I'm finding it very difficult to actually achieve this. Can anyone
help?
What is happening:
JsonConvert is a library I use made by NewtonSoft to convert the object to
json for returning.
The asmx is being hosted on domain b.company.com
The client ajax call is hosted on domain a.compay.com
Fiddler is picking up for the single call two(2) 401 then a 200 which is
not viewable in the JSON tab of the reply.
This is the 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 is a 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 is the fiddler "Raw" view of the response:
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Encoding: gzip
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 oRswGaADCgEAoxIEEAEAAAAN+RE6iL3QVwAAAAA=
Date: Thu, 15 Aug 2013 22:29:02 GMT
Content-Length: 235
��������`I�%amp;/m�{J�J��t��`$ؐ@������iG#)�*��eVe]f@�흼��{���{���;�N'���?\fdl��J�ɞ!���?~|?��ez��MQ-?�hw��Q�/�լX^|�Ѻ=�gt;���8����M[�G)�^6�}4o�գ�w��b�L�e1m�u݌����GG����m֮��}�����裧Y�����˲JO^}��/y|W��?��E���
/code/pre
No comments:
Post a Comment