From 2d2b34b736c49939f868fd55727dc53e719e7c7f Mon Sep 17 00:00:00 2001 From: Konstantin Date: Tue, 6 May 2014 11:51:52 -0400 Subject: [PATCH 1/4] added note on triggered preflight When you define a specific contentType in an $.ajax request, jquery will send a CORS preflight OPTIONS request. This is somewhat "hidden" behaviour that can often cause headaches unless its documented. --- entries/jQuery.ajax.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entries/jQuery.ajax.xml b/entries/jQuery.ajax.xml index 3b70d572..953d74ed 100644 --- a/entries/jQuery.ajax.xml +++ b/entries/jQuery.ajax.xml @@ -38,7 +38,7 @@ An object of string/regular-expression pairs that determine how jQuery will parse the response, given its content type. - When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding. + When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding. Note: Setting the content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or text/plain will trigger a CORS preflight OPTIONS request to the server. This object will be made the context of all Ajax-related callbacks. By default, the context is an object that represents the ajax settings used in the call ($.ajaxSettings merged with the settings passed to $.ajax). For example, specifying a DOM element as the context will make that the context for the complete callback of a request, like so: From 31cacc01e115348ecdebc9402348e4a7787d929d Mon Sep 17 00:00:00 2001 From: Konstantin Date: Tue, 6 May 2014 11:55:09 -0400 Subject: [PATCH 2/4] wrapping code-related text in --- entries/jQuery.ajax.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entries/jQuery.ajax.xml b/entries/jQuery.ajax.xml index 953d74ed..a405b307 100644 --- a/entries/jQuery.ajax.xml +++ b/entries/jQuery.ajax.xml @@ -38,7 +38,7 @@ An object of string/regular-expression pairs that determine how jQuery will parse the response, given its content type. - When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding. Note: Setting the content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or text/plain will trigger a CORS preflight OPTIONS request to the server. + When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding. Note: Setting the content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or text/plain will trigger a CORS preflight OPTIONS request to the server. This object will be made the context of all Ajax-related callbacks. By default, the context is an object that represents the ajax settings used in the call ($.ajaxSettings merged with the settings passed to $.ajax). For example, specifying a DOM element as the context will make that the context for the complete callback of a request, like so: From f13e98bd3b54a08a493afa401277879b8897b779 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Tue, 6 May 2014 13:59:14 -0400 Subject: [PATCH 3/4] OPTIONS is made only in cross-domain requests --- entries/jQuery.ajax.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entries/jQuery.ajax.xml b/entries/jQuery.ajax.xml index a405b307..5c3af1ad 100644 --- a/entries/jQuery.ajax.xml +++ b/entries/jQuery.ajax.xml @@ -38,7 +38,7 @@ An object of string/regular-expression pairs that determine how jQuery will parse the response, given its content type. - When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding. Note: Setting the content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or text/plain will trigger a CORS preflight OPTIONS request to the server. + When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding. Note: For cross-domain requests, setting the content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or text/plain will trigger a CORS preflight OPTIONS request to the server. This object will be made the context of all Ajax-related callbacks. By default, the context is an object that represents the ajax settings used in the call ($.ajaxSettings merged with the settings passed to $.ajax). For example, specifying a DOM element as the context will make that the context for the complete callback of a request, like so: From 1a11ee62c801078c2dea1181f58e554663733b2a Mon Sep 17 00:00:00 2001 From: Konstantin Date: Fri, 30 May 2014 11:56:27 -0400 Subject: [PATCH 4/4] Making it clear that browsers, not jQuery trigger an OPTIONS request --- entries/jQuery.ajax.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entries/jQuery.ajax.xml b/entries/jQuery.ajax.xml index 5c3af1ad..287395aa 100644 --- a/entries/jQuery.ajax.xml +++ b/entries/jQuery.ajax.xml @@ -38,7 +38,7 @@ An object of string/regular-expression pairs that determine how jQuery will parse the response, given its content type. - When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding. Note: For cross-domain requests, setting the content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or text/plain will trigger a CORS preflight OPTIONS request to the server. + When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding. Note: For cross-domain requests, setting the content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or text/plain will trigger the browser to send a preflight OPTIONS request to the server. This object will be made the context of all Ajax-related callbacks. By default, the context is an object that represents the ajax settings used in the call ($.ajaxSettings merged with the settings passed to $.ajax). For example, specifying a DOM element as the context will make that the context for the complete callback of a request, like so: