I have an AJAX Enabled REST Web Service self hosted at http://localhost/machinename/ and a test project running at http://localhost:59103/ hosted on a .NET Development Server. I’ve added my script reference to my test project and referenced the js ( http://localhost/machinename/js/ ) however, when the REST calls are invoked, it keeps trying to call http://localhost:59103/machinename/Method/, which doesn’t exist because that’s not where my service is hosted, and it’s not where I’m telling it my service exists.
My question is 2 fold:
- Why doesn’t it call out to the correct endpoint?
- Can I make it call out to the correct endpoint?
I think this has to do with the JavaScript sandbox security model, where JS is only allowed to issue requests to the origin server from which the page (not the JS script!) was loaded. This seems to happen in your case: The host identifier is stripped out of the URI.
This is a known issue, of course. You might want to look at JSONP as one possible way around this.