Fixed an issue with getJSON (type was not correctly passed on when data was ommited); Added more options to $.ajax to provide more flexibility (bug #371)
This commit is contained in:
parent
06c185321c
commit
1e620109d7
2 changed files with 20 additions and 13 deletions
|
@ -8,5 +8,5 @@ h2 { padding: 10px; background-color: #eee; color: black; margin: 0; font-size:
|
||||||
p.result { margin-left: 1em; }
|
p.result { margin-left: 1em; }
|
||||||
|
|
||||||
#banner { height: 2em; }
|
#banner { height: 2em; }
|
||||||
#banner.pass { background-color: green }
|
div.pass { background-color: green; }
|
||||||
#banner.fail { background-color: red; }
|
div.fail { background-color: red; }
|
|
@ -342,7 +342,6 @@ jQuery.extend({
|
||||||
get: function( url, data, callback, type, ifModified ) {
|
get: function( url, data, callback, type, ifModified ) {
|
||||||
// shift arguments if data argument was ommited
|
// shift arguments if data argument was ommited
|
||||||
if ( data && data.constructor == Function ) {
|
if ( data && data.constructor == Function ) {
|
||||||
type = callback;
|
|
||||||
callback = data;
|
callback = data;
|
||||||
data = null;
|
data = null;
|
||||||
}
|
}
|
||||||
|
@ -466,11 +465,7 @@ jQuery.extend({
|
||||||
* @cat AJAX
|
* @cat AJAX
|
||||||
*/
|
*/
|
||||||
getJSON: function( url, data, callback ) {
|
getJSON: function( url, data, callback ) {
|
||||||
if(callback)
|
jQuery.get(url, data, callback, "json");
|
||||||
jQuery.get(url, data, callback, "json");
|
|
||||||
else {
|
|
||||||
jQuery.get(url, data, "json");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -597,8 +592,6 @@ jQuery.extend({
|
||||||
*
|
*
|
||||||
* (String) url - The URL of the page to request.
|
* (String) url - The URL of the page to request.
|
||||||
*
|
*
|
||||||
* (String) data - Data to be sent to the server. If converted to a query
|
|
||||||
* string, if not already a string. Is appended to the url for GET-requests.
|
|
||||||
*
|
*
|
||||||
* (String) dataType - The type of data that you're expecting back from
|
* (String) dataType - The type of data that you're expecting back from
|
||||||
* the server (e.g. "xml", "html", "script", or "json").
|
* the server (e.g. "xml", "html", "script", or "json").
|
||||||
|
@ -627,6 +620,18 @@ jQuery.extend({
|
||||||
* function gets passed two arguments: The XMLHttpRequest object and a
|
* function gets passed two arguments: The XMLHttpRequest object and a
|
||||||
* string describing the type the success of the request.
|
* string describing the type the success of the request.
|
||||||
*
|
*
|
||||||
|
* (String) data - Data to be sent to the server. Converted to a query
|
||||||
|
* string, if not already a string. Is appended to the url for GET-requests.
|
||||||
|
* Override processData option to prevent processing.
|
||||||
|
*
|
||||||
|
* (String) contentType - When sending data to the server, use this content-type,
|
||||||
|
* default is "application/x-www-form-urlencoded", which is fine for most cases.
|
||||||
|
*
|
||||||
|
* (Boolean) processData - By default, data passed in as an object other as string
|
||||||
|
* will be processed and transformed into a query string, fitting to the default
|
||||||
|
* content-type "application/x-www-form-urlencoded". If you want to send DOMDocuments,
|
||||||
|
* set this option to false.
|
||||||
|
*
|
||||||
* @example $.ajax({
|
* @example $.ajax({
|
||||||
* type: "GET",
|
* type: "GET",
|
||||||
* url: "test.js",
|
* url: "test.js",
|
||||||
|
@ -708,14 +713,16 @@ jQuery.extend({
|
||||||
success: null,
|
success: null,
|
||||||
error: null,
|
error: null,
|
||||||
dataType: null,
|
dataType: null,
|
||||||
|
url: null,
|
||||||
data: null,
|
data: null,
|
||||||
url: null
|
contentType: "application/x-www-form-urlencoded",
|
||||||
|
processData: true
|
||||||
}, s);
|
}, s);
|
||||||
|
|
||||||
// if data available
|
// if data available
|
||||||
if ( s.data ) {
|
if ( s.data ) {
|
||||||
// convert data if not already a string
|
// convert data if not already a string
|
||||||
if (typeof s.data != 'string')
|
if (s.processData && typeof s.data != 'string')
|
||||||
s.data = jQuery.param(s.data);
|
s.data = jQuery.param(s.data);
|
||||||
// append data to url for get requests
|
// append data to url for get requests
|
||||||
if( s.type.toLowerCase() == "get" )
|
if( s.type.toLowerCase() == "get" )
|
||||||
|
@ -737,7 +744,7 @@ jQuery.extend({
|
||||||
|
|
||||||
// Set the correct header, if data is being sent
|
// Set the correct header, if data is being sent
|
||||||
if ( s.data )
|
if ( s.data )
|
||||||
xml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
xml.setRequestHeader("Content-Type", s.contentType);
|
||||||
|
|
||||||
// Set the If-Modified-Since header, if ifModified mode.
|
// Set the If-Modified-Since header, if ifModified mode.
|
||||||
if ( s.ifModified )
|
if ( s.ifModified )
|
||||||
|
|
Loading…
Reference in a new issue