0

I know that there are four request types such as get ,put ,post ,delete .When and why will I use type='put' or type="post" ?Basically what are the differences between them?

$.ajax({
    url: '<?php echo site_url('rest_api / contacts ')."?format=json"; ?>',
    type: "put",
    data: $('#subpanel-contacts-add-form').serialize(),
    success: function (response) {
        //some tasks
    }
    error: function () {
        $("#subpanel-contacts-form-result").html('<div class="alert alert-error">Error: There  was an error while submitting!</div>');
    }
});
sharif2008
  • 2,470
  • 1
  • 17
  • 32

1 Answers1

1

PUT and GET are the protocols to exchange data between the server and UI define by the standard committee.

Type attribute in the $.ajax function in the way to tell the engine that what kind of request is being generated and accordingly it is handled on the server side.

Refer to the link posted below for more explanation and difference between the protocols.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

Akhilesh Sharma
  • 1,488
  • 1
  • 16
  • 26
  • can i do the same task with get which can be done with put? – sharif2008 Jun 10 '13 at 06:46
  • 1
    The handling of the protocols are different but the last result is the same as they are used to process the data. The document link posted will help you to choose the type of protocol that is used. If you are using sensitive data then it will be better that you use POST rather than GET as in case of GET the data is sent to the server using the query string. – Akhilesh Sharma Jun 10 '13 at 06:48