Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery 1.5 only sends GET requests in ajax method

I am trying to make a PUT request to a RESTful web service, however, it appears that jQuery 1.5 does respond to any changes in the 'type' setting. The request is sent as a GET no matter the value in 'type'. In jQuery 1.4 this isn't a problem.

Here's my code:

$.ajax({
    type: "PUT",
    url: "https://api.somesite.com/v1.0/people/" + individualID + "/",
    dataType: "jsonp",
    data: $("#editProfile").serializeArray(),
    cache: "false",
    success: function(data,textStatus,jqXHR) {
        $.modal.close();
    },
    error: function(jqXHR,textStatus,errorThrown) {
        alert("Error!");
    }
});
like image 803
Austin Avatar asked Feb 05 '11 19:02

Austin


People also ask

What is the difference between jQuery get () and jQuery AJAX ()?

get() executes an Ajax GET request. The returned data (which can be any data) will be passed to your callback handler. $(selector). load() will execute an Ajax GET request and will set the content of the selected returned data (which should be either text or HTML).

Does AJAX use Get or POST?

Because “Ajax” requests are subject to the same origin policy there is limited security risks when using GET instead of POST. Use GET to “GET” information from the server such as loading a JavaScript file (AJAX shorthand function $. getScript() can be used to do this) or loading a JSON file (AJAX shorthand function $.

Can we send data in GET method?

The GET method is the method used by the browser to ask the server to send back a given resource: "Hey server, I want to get this resource." In this case, the browser sends an empty body. Because the body is empty, if a form is sent using this method the data sent to the server is appended to the URL.

Should I use jQuery for AJAX?

So, the real question is: should you use jQuery to perform your Ajax requests? And the answer is: yes, if you're already using jQuery - if not, you can include jQuery or another Ajax-supporting JS library, or you can implement the Ajax functionality in vanilla JS. Save this answer.


1 Answers

As far as I'm aware, you can't make a JSONP request via PUT. Since JSONP works by injecting a <script> element pointing to the remote domain, that request will always be a GET request.

If you absolutely must make a PUT request to a remote domain, you'll need to either use a server-side proxy on your local domain or look into CORS if you don't need IE support.

like image 127
Dave Ward Avatar answered Oct 01 '22 07:10

Dave Ward