1

I can not connect to a Web service, tried a lot of different options and change parameters, prompt where to dig? This is my first experience of connecting via AJAX, I tried through other clients work.

var xhr = $.ajax({
     url: webserUrl,
     type: "GET",
     data: JSON.stringify({ "Tabn": "1","Vaccurrent": "1","Vacnext": "1" }),
     cache: false,
     crossDomain: true,
     username: "user", 
     password: "password",
     processData: false,
     contentType: "application/json",
     dataType: "json",
     headers: {
        "Accept": "application/json; odata=verbose"
    },
     xhrFields: {
     withCredentials: true
                },
     crossDomain: true,
      success: OnSuccess, 
      error: OnError
        });
function OnSuccess(data, status) { alert(data); } function OnError(xhr, ajaxOptions, thrownError, request, error) { alert('xrs.status = ' + xhr.status + '\n' + 'thrown error = ' + thrownError + '\n' + 'xhr.statusText = ' + xhr.statusText + '\n' + 'request = ' + request + '\n' + 'error = ' + error); console.log('xrs.status = ' + xhr.status + '\n' + 'thrown error = ' + thrownError + '\n' + 'xhr.statusText = ' + xhr.statusText + '\n' + 'request = ' + request + '\n' + 'error = ' + error); }
});

Error:
xrs.status = 200
thrown error = undefined
xhr.statusText = OK
request = undefined
error = undefined

2
  • So what does the xhr.responseText look like? Commented Dec 28, 2015 at 21:28
  • Since you're getting a 200 response code, the HTTP request is going through correctly. I suspect the server isn't returning a JSON response, so jQuery is getting an error when it tries to parse the response. Commented Dec 28, 2015 at 21:30

2 Answers 2

1

Thank you all for your answers, changed to a url with wsdl endpoint, also changed the content type to: "text / xml; charset = \" utf-8 \ "" and it worked.

Sign up to request clarification or add additional context in comments.

1 Comment

So are you returning XML to your Ajax? And if you return JSON as a result, you must use application/json as contentType.
0

xrs.status = 200 means the server accepted the request, thus the problem might be on the client side, and most likely is caused by the "Accept": "application/json; odata=verbose" header, which instructs jquery to reject the server response if it didn't sent a json as a response.

You need to check what data is the server responding by using the developer tools your browser provides.

2 Comments

What and how you can check the last statement?
@MikhailZhuykov If you're using Chrome, here's the link, you're interested about the Network tab, for Firefox I recommend Firebug

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.