AJAX HTTP response issue with custom server

I started adding HTTP support to a custom non-C # webserver application that seems to work fine with Firefox / IE / Chrome when entering a URL directly into the browser - wherever I see the returned text string in pages from mine applications.

The problem is I am trying to do the same from HTTPRequest in JavaScript on a web page. I am not getting a response from Chrome or Firefox (this is fine in IE) - rather, I am getting a status of zero from the HTTPRequest object, However, I can see that my application, from its debug output, received a request from the browser and provided a response so that the browser does not look like the answer I post in this case, except IE is less picky.

I swapped between trying different POST and GET requests to no avail - e.g .:

request.open ('GET', url, true); request.onreadystatechange = mycallback; //request.setRequestHeader('Content-type ',' application / x-www-form-urlencoded '); request.send (null); // tried '' and other data with POST

Simplest server response I've tried:

HTTP / 1.1 200 OK \ r \ n Content-Length: 20 \ r \ n Content-Type: text / plain \ r \ n \ Y \ n ...........

I tried 1.0 instead of 1.1, different headers like Connection: Close, Accept-range and other random stuff as I tried to mimic other similar answers I was looking at with Wireshark.

Obviously it should be something simple, but the magic combination eludes me!

Thank you very much in advance.

+2


a source to share


1 answer


And on that note I answered my own question, it was a cross domain security feature.

Now I fixed adding an additional response header:



"Access-Control-Allow-Origin: *"

Hope this will be helpful for someone else in the future!

+2


a source







All Articles