Commit 1bc9f8ca 1bc9f8cab38353d7412ec028b76a20fb04b09f4e by Rock Li

add new parameter settings to sendAJAX, so we can override the default content t…

…ype when sending out ajax requests

Some sites don't accept the default content-type "application/x-www-form-urlencoded", must send out the specific content-type.
so we need the extra settings to override the default content-type setting in current sendAJAX implementation.
1 parent 81f8744b
......@@ -315,7 +315,7 @@ Removes all DOM elements matching a given :ref:`XPath expression <selectors>`.
``sendAJAX()``
-----------------------------------------------------------------------------
**Signature:** ``sendAJAX(String url[, String method, Object data, Boolean async])``
**Signature:** ``sendAJAX(String url[, String method, Object data, Boolean async, Object settings])``
.. versionadded:: 1.0
......@@ -325,6 +325,7 @@ Sends an AJAX request, using the following parameters:
- ``method``: The HTTP method (default: ``GET``).
- ``data``: Request parameters (default: ``null``).
- ``async``: Flag for an asynchroneous request? (default: ``false``)
- ``settings``: Other settings when perform the AJAX request (default: ``null``)
.. warning::
......
......@@ -628,17 +628,19 @@
/**
* Performs an AJAX request.
*
* @param String url Url.
* @param String method HTTP method (default: GET).
* @param Object data Request parameters.
* @param Boolean async Asynchroneous request? (default: false)
* @return String Response text.
* @param String url Url.
* @param String method HTTP method (default: GET).
* @param Object data Request parameters.
* @param Boolean async Asynchroneous request? (default: false)
* @param Object settings Other settings when perform the ajax request
* @return String Response text.
*/
this.sendAJAX = function sendAJAX(url, method, data, async) {
this.sendAJAX = function sendAJAX(url, method, data, async, settings) {
var xhr = new XMLHttpRequest(),
dataString = "",
dataList = [];
method = method && method.toUpperCase() || "GET";
var contentType = settings && settings.contentType || "application/x-www-form-urlencoded";
xhr.open(method, url, !!async);
this.log("sendAJAX(): Using HTTP method: '" + method + "'", "debug");
xhr.overrideMimeType("text/plain; charset=x-user-defined");
......@@ -652,7 +654,7 @@
} else if (typeof data === "string") {
dataString = data;
}
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-Type", contentType);
}
xhr.send(method === "POST" ? dataString : null);
return xhr.responseText;
......