$.ajax({
type: 'POST',
url: path,
data: '{AreaID: ' + parentDropdownList.val() + '}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(response)
{
}
});
In above code I am using type: ‘POST’. My senior told me that I also can use ‘GET’ in type. But dint find the difference between ‘POST’ and ‘GET’ and I also want to know what is the use of type, contentType, and dataType.
Could anyone one explain me why we use these type, contentType and dataType.
Thanks in advance.
These are some of the fundamentals of web communication:
Have a read here: http://javascript.about.com/od/ajax/a/ajaxgp.htm
Essentially GET creates a query string (www.mysite.co.uk/mypage?id=1%name=john%something=anothervalue etc.etc.). This means that it is possible to invoke a GET request directly from the URL on a browser. Web servers actually cache the results of GET requests for performance reasons. There are very much designed for data retrieval.
POST actually sends the data directly to the server and the result is never cached.
I’d always suggest using something like Firebug for Firefox or the Web Development Helper for IE so that you can see the data transfer between client and server.
As a rule of thumb, use GET to retrieve data and POST to update it.
Also, see a great answer to the same question here: GET vs POST in AJAX?