1

I am trying to send the data via ajax POST method my code is

$.ajax({
            url: myUrl + "?token=" + accessToken + "&key=" +dev_key,
            dataType: 'jsonp',
            type: 'POST',
            data: sendXML,
            success: function () {
            alert("z");
            }
        });

But the type: 'POST' is not working I am getting the following error on console:

Status Code:405 HTTP method GET is not supported by this URL

  • what is the value of the final url – Royi Namir Feb 27 '12 at 09:56
  • @Ayesha you have specified the dataType as jsonp why is that? usually the jsonp requests are GET type, what server side language you are using, can you post the server side code that is handling the ajax request – Rafay Feb 27 '12 at 09:57
  • But I want POST cz I want to hit other site on different domain –  Feb 27 '12 at 09:59
  • 1
    possible duplicate of [Post data to JsonP](http://stackoverflow.com/questions/2699277/post-data-to-jsonp) – Royi Namir Feb 27 '12 at 10:00
  • @Ayesha does the other domain allow hitting via jsonp? have you confirmed that, also what is the final url that is outputted? and as i said jsonp requests are GET type you cannot make a POST to them – Rafay Feb 27 '12 at 10:01
  • @3nigma I want to hit youtube I donot know is JSONP enabled or not on youtube –  Feb 27 '12 at 10:03

2 Answers2

1

Have you tried using $.post ?

Example:

$.post(
    myUrl,
    {
        token: accessToken,
        key: dev_key
    },
    function(result){
        alert(z)
    }
)

P.S. Isn't ? missing after myUrl?

siannone
  • 6,617
  • 15
  • 59
  • 89
  • Question mark is included in my url it dose not make affect i checked it –  Feb 27 '12 at 09:58
1

i think you forgot the ? in the token key like this

mySql + "?token="

otherwise, try this:

jQuery.post(
    myUrl + "?token=" + accessToken + "&key=" +dev_key,
    sendXML,
    function() {
        alert('z');
    },
    'JSONP'
);
silly
  • 7,789
  • 2
  • 24
  • 37