Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Ajax GET and contentType?

Tags:

jquery

Regarding : (jQuery ajax method) :

Does contentType property is counted when the request itself is a GET request ? (example)

$.ajax({
    type: "GET",
    url: "/webservices/xxx.asmx/yyy",
    data: JSON.stringify({ Markers: markers }),
    contentType: "application/json; charset=utf-8",
    dataType: "json",.......

});

p.s.

contentType is the form of data which i send to the server
dataType is the form of data which i EXPECT to get from server.

like image 915
Royi Namir Avatar asked Jul 18 '13 13:07

Royi Namir


People also ask

What is Content-Type in AJAX?

contentType is the type of data you're sending, so application/json; charset=utf-8 is a common one, as is application/x-www-form-urlencoded; charset=UTF-8 , which is the default. dataType is what you're expecting back from the server: json , html , text , etc.

How can I get specific data from AJAX response?

You can't as it's asynchronous. If you want to do anything with it, you need to do it in a callback. How? Because it's asynchronous, javascript will fire off the ajax request, then immediately move on to execute the next bit of code, and will probably do so before the ajax response has been received.

What is Content-Type false in AJAX?

contentType option to false is used for multipart/form-data forms that pass files. When one sets the contentType option to false , it forces jQuery not to add a Content-Type header, otherwise, the boundary string will be missing from it.


1 Answers

According to the RFC 2616, it's not forbidden to use the request body in GET requests.
However, I'd like to know of an client implementation which does send data in the body and an server implementation which parses data in the body of GET requests.

So basically, no, the Content-Type header is not used.

like image 79
gustavohenke Avatar answered Oct 12 '22 02:10

gustavohenke