views:

17

answers:

1

I've started to add HTTP support to a custom C# non-webserver application which seems to work fine from Firefox/IE/Chrome when typing in the URL directly to the browser - where I can see a returned text string in the page from my application.

The problem is when I try do the same from a HTTPRequest in JavaScript on a web page I don't get a response with Chrome or Firefox (It's fine in IE) - rather I get a status of zero from the HTTPRequest object. I can however see that my application from its debug output received the request from the browser and provided the response so the browser must not be like the response I send in this case with the exception of IE being less picky.

I've swapped between trying different POST and GET requests to no avail - eg:

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

My simplest server reply I have tried is:

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

I have tried 1.0 instead of 1.1, different headers such as Connection: Close, Accept-ranges and other random stuff as I tried to mimic other such responses I looked at with Wireshark.

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

Many thanks in advance.

+1  A: 

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

Which I have now fixed by adding the extra response header:

"Access-Control-Allow-Origin: *"

Hopefully that is useful for someone else in the future!

wb
I should note that may not work in some older versions of Firefox (Not sure on Chrome) but is fine for my needs.
wb