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>'); } }); 
4

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

can i do the same task with get which can be done with put?
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.