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
Jsonp isn’t designed to be used with
POSTrequests (see the answer to this question), so I suspect that thedataType: "jsonp"is causing the request to be sent asGETrather thanPOST. 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.