This is how I set the xmlhttp
:
xmlhttp = new XMLHttpRequest();
I followed the instructions in this post that explains how to send a POST request.
xmlhttp.open("POST", url, false);//false means synchronous
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.withCredentials = true;
xmlhttp.send(postData);// This line throws Network Error exception.
Notes:
This URL is a .asmx
web service.
This web service works fine, when I try to get data from it using the browser.
When I try running this code in the same domain where the web service is located, the code runs fine, and returns the data as I expect.
Most of my code, is based on async calls in which the same problem occurs, this example is sync only for simplicity.
My problem:
When I try to run this code from localhost, the line that I mentioned throws an exception. I checked the actual response that returns from the web service, and turns out that it contains the data it should.
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
Persistent-Auth: true
X-Powered-By: ASP.NET
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST
Access-Control-Allow-Headers: Origin,cache-control,content-type,man,messagetype,soapaction
Date: Mon, 09 Dec 2013 18:20:03 GMT
Content-Length: 563
The actual data exists here in the response....
Edit:
When I use async call, the request is ended with status 0 but it still has the data.