0

I'm trying to understand some of jQuery.ajax() settings:

ajaxOb.processData = false;
ajaxOb.contentType = false;
ajaxOb.cache = false;

Some of the settings I think understand correctly, I just need confirmation that I'm correct on these settings.

My server requests for those settings are for binary type file.

.processData:

As i understand because the default content-type header value is application/x-www-form-urlencoded if processData won't be set to false, jQuery will convert the data option into string to fit the content-type default value.

.contentType:

I found some explanations of why use it, But i am looking for examples to see the header, If can someone explain it widely, Show some header examples when contentType = true and when contentType = false.

.cache

About the cache according to jQuery.ajax(), The only reason I'm using cache = false although I'm using POST, In IE8 the POST is made to a URL that has already been requested by a GET.

I don't know if I understand this sentence right so I don't want to say stupid things so if anyone can explain what will happen in IE8 when cache = true.

Thank you all and have a nice day.


Update:

So about contentType = false, My main problem was to understand what boundary is, Now after i found the answer here What is the boundary parameter in an HTTP multi-part (POST) Request? the only thing i need to understand is: From jQuery.ajax() about cache option:

If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.

This is what i can't understand:

except in IE8 when a POST is made to a URL that has already been requested by a GET.

If anyone can explain this line, I will be very thankful.

Community
  • 1
  • 1
Aviel Fedida
  • 4,004
  • 9
  • 54
  • 88
  • I think these are pretty well explained in the documentation, and their names make it pretty self explanatory. processData simply tells jquery to either parse the data passed in, or to leave it alone and instead send it in the request body as is (if it can.) contentType is the contentType used to SEND the data to the server. cache is a flag that simply adds a queryparam to the url to prevent caching if it is set to false. cache set to true does absolutely nothing other than NOT adding said queryparam. – Kevin B Dec 20 '13 at 16:41
  • http://api.jquery.com/jQuery.ajax/ – Kevin B Dec 20 '13 at 16:46
  • 1
    I think you misunderstood the `contentType` option. It doesn't accept a boolean value, but a string. It's how you define in which format the data you send is in. The default value is `'application/x-www-form-urlencoded; charset=UTF-8'`, but if you send your data as JSON, you should set it to `'application/json'`. – Felix Kling Dec 20 '13 at 16:48
  • @Felix i understand what you mean but if you look at this answer: http://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax/5976031#5976031 you will understand why i set contentType = false – Aviel Fedida Dec 20 '13 at 17:17
  • Ah, I didn't know about that. But anyways, now you know when to set it to false or to another value :) – Felix Kling Dec 20 '13 at 17:44

0 Answers0