Amit
Amit

Reputation: 26316

Not able to send POST request through jQuery Ajax

I was trying to send an ajax request as POST request. But when i verified it on httpFox on firefox, the request is sent as GET. I tried both $.ajax() and $.post().

Many had a query regarding the same and had missed the "type" in $.ajax(), but even if i mention the type as "POST", the request will be of type GET. Here is my code:

$('.test').click(function(){
   alert("clicked");
   $.ajax({
   type: "POST",
   url: "www.testsite.com",
   data: "name=John&location=Boston",
success: function(msg){
    alert( "Data Saved: " + msg );
}
});
 });

Any idea why it happens?

Upvotes: 1

Views: 1688

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039398

A possible cause might be the fact that you are trying to send an AJAX request to a different domain: www.testsite.com than the one hosting your page which of course is not possible and jQuery tries to use JSONP instead which works only with HTTP GET.

Upvotes: 3

Related Questions