1

been banging my head against the wall with this one.

Need to POST to a RESTful web service. Username goes in the request url. Password goes in the request body. Content-type must be application/x-www-form-urlencoded.

Using the Chrome "Simple REST Client" extension, everything is working fine.

Using jQuery.AJAX(), I continually get a 405 (Method Not Allowed) error.

Okay, here's the code:


    $.ajax({
       type: "POST",
       contentType: "application/x-www-form-urlencoded",
       url: baseURL + "api/users/" + username + "/login",     
       data: { password: password },
       success: function(data) {
            console.log("success ", data.response);
        },
        error: function(data) {
            console.log("error ", data.error);
        },
        dataType: "jsonp"               
    });

Does anyone see anything that is wrong with the code?

Thanks, Jacob

Urs Reupke
  • 6,791
  • 3
  • 35
  • 49
jacobdubail
  • 194
  • 2
  • 13

1 Answers1

1

Jsonp isn't designed to be used with POST requests (see the answer to this question), so I suspect that the dataType: "jsonp" is causing the request to be sent as GET rather than POST. You can confirm this behaviour using the "net" panel in Firebug or the Chrome developer console.

What do you expect the server to return? You might be able to fix it by dropping the dataType, or setting it to some other value.

Community
  • 1
  • 1
Timothy Jones
  • 21,495
  • 6
  • 60
  • 90