Wednesday, August 28, 2013

Backbone: Request Method:OPTIONS Status Code:405 Method Not Allowed trying to do a POST request with collection.fetch

I had this code:

this.organizationServicesCollection.url = 'http://localhost/SkyDesk.Services/SrvService.svc/rest/service/queryservices/'        
var fetchParameters = {
data: JSON.stringify({
    parameters: {'key':'value'}
}),
        type: 'POST',
        contentType: 'application/json'
};
this.organizationServicesCollection.fetch(fetchParameters);

when executed I was having two resulting requests:

Request URL:http://localhost/SkyDesk.Services/SrvService.svc/rest/service/queryservices/
Request Method:OPTIONS

Request URL:http://localhost/SkyDesk.Services/SrvService.svc/rest/service/queryservices/
Request Method:POST

The problem was that my current proyect was being run in http://localhost:49998/ instead http://localhost/ so there was a cross domain issue. I fixed it running my project in http://localhost/ , now when running the code I had my single POST request:

Request URL:http://localhost/SkyDesk.Services/SrvService.svc/rest/service/queryservices/
Request Method:POST

No comments: