1

I am trying to run this script from localhost but it gets an error 405 (Method Not Allowed) .

Code

$(document).ready(function(){

    $.ajax({
        url:'http://some.url/',
        type:'post',
        //crossDomain: true,
        data:'{id:"49"}',
        contentType: "application/json; charset=utf-8",
        dataType:'jsonp',

            success: function(responseData, textStatus, jqXHR) {
                alert('right');
                var value = responseData.someKey;
                console.log(value);
            },
            error:function() {
                alert("Sorry, I can't get the feed");  
            }
    });
});

I have tried with crossDomain:true and $.support.cors = true, but of no use.Any ideas?

Mike-O
  • 844
  • 1
  • 11
  • 16
Gopesh
  • 3,882
  • 11
  • 37
  • 52

1 Answers1

2

That has nothing to do with CORS, HTTP 405 means that your HTTP method is not permitted, e.g. GET, POST, etc.

According to Chrome dev tools, only POST and OPTIONS are permitted HTTP methods.

Chrome dev tools response headers

To send a POST request using jQuery.ajax(), use the following:

$.ajax('url', {
    // other settings here
    type: 'POST'
}

You can also use the jQuery.post() wrapper method to do the same thing.

Note that the particular site in question has not setup cross-origin support, therefore if you need to access this, you'll need to get the site to fix this issue or you'll need to use your server as a proxy.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83