mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Refactored all logic from $.get and $.post into $.ajax, now they are only convenience delegators
This commit is contained in:
parent
d8fb555970
commit
7ff54c4034
@ -141,6 +141,15 @@ jQuery.fn.extend({
|
|||||||
return jQuery.param( this );
|
return jQuery.param( this );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluate all script tags inside this jQuery. If they have a src attribute,
|
||||||
|
* the script is loaded, otherwise it's content is evaluated.
|
||||||
|
*
|
||||||
|
* @name evalScripts
|
||||||
|
* @type jQuery
|
||||||
|
* @private
|
||||||
|
* @cat AJAX
|
||||||
|
*/
|
||||||
evalScripts: function() {
|
evalScripts: function() {
|
||||||
return this.find('script').each(function(){
|
return this.find('script').each(function(){
|
||||||
if ( this.src )
|
if ( this.src )
|
||||||
@ -331,22 +340,20 @@ jQuery.extend({
|
|||||||
* @cat AJAX
|
* @cat AJAX
|
||||||
*/
|
*/
|
||||||
get: function( url, data, callback, type, ifModified ) {
|
get: function( url, data, callback, type, ifModified ) {
|
||||||
|
// shift arguments if data argument was ommited
|
||||||
if ( data && data.constructor == Function ) {
|
if ( data && data.constructor == Function ) {
|
||||||
type = callback;
|
type = callback;
|
||||||
callback = data;
|
callback = data;
|
||||||
data = null;
|
data = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// append ? + data or & + data, in case there are already params
|
// Delegate
|
||||||
if ( data ) url += ((url.indexOf("?") > -1) ? "&" : "?") + jQuery.param(data);
|
|
||||||
|
|
||||||
// Build and start the HTTP Request
|
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
ifModified: ifModified,
|
data: data,
|
||||||
complete: function(r, status) {
|
success: callback,
|
||||||
if ( callback ) callback( jQuery.httpData(r,type), status );
|
dataType: type,
|
||||||
}
|
ifModified: ifModified
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -502,14 +509,13 @@ jQuery.extend({
|
|||||||
* @cat AJAX
|
* @cat AJAX
|
||||||
*/
|
*/
|
||||||
post: function( url, data, callback, type ) {
|
post: function( url, data, callback, type ) {
|
||||||
// Build and start the HTTP Request
|
// Delegate
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: url,
|
url: url,
|
||||||
data: jQuery.param(data),
|
data: data,
|
||||||
complete: function(r, status) {
|
success: callback,
|
||||||
if ( callback ) callback( jQuery.httpData(r,type), status );
|
dataType: type
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -690,39 +696,31 @@ jQuery.extend({
|
|||||||
* @param Hash prop A set of properties to initialize the request with.
|
* @param Hash prop A set of properties to initialize the request with.
|
||||||
* @cat AJAX
|
* @cat AJAX
|
||||||
*/
|
*/
|
||||||
//ajax: function( type, url, data, ret, ifModified ) {
|
|
||||||
ajax: function( s ) {
|
ajax: function( s ) {
|
||||||
|
// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
|
||||||
var fvoid = function() {};
|
|
||||||
s = jQuery.extend({
|
s = jQuery.extend({
|
||||||
global: true,
|
global: true,
|
||||||
ifModified: false,
|
ifModified: false,
|
||||||
type: "GET",
|
type: "GET",
|
||||||
timeout: jQuery.timeout,
|
timeout: jQuery.timeout,
|
||||||
complete: fvoid,
|
complete: null,
|
||||||
success: fvoid,
|
success: null,
|
||||||
error: fvoid,
|
error: null,
|
||||||
dataType: null,
|
dataType: null,
|
||||||
data: null,
|
data: null,
|
||||||
url: null
|
url: null,
|
||||||
}, s);
|
}, s);
|
||||||
|
|
||||||
/*
|
// if data available
|
||||||
// If only a single argument was passed in,
|
if ( s.data ) {
|
||||||
// assume that it is a object of key/value pairs
|
// convert data if not already a string
|
||||||
if ( !url ) {
|
if (typeof s.data != 'string')
|
||||||
ret = type.complete;
|
s.data = jQuery.param(s.data)
|
||||||
var success = type.success;
|
// append data to url for get requests
|
||||||
var error = type.error;
|
if( s.type.toLowerCase() == "get" )
|
||||||
var dataType = type.dataType;
|
// "?" + data or "&" + data (in case there are already params)
|
||||||
var global = typeof type.global == "boolean" ? type.global : true;
|
s.url += ((s.url.indexOf("?") > -1) ? "&" : "?") + s.data;
|
||||||
var timeout = typeof type.timeout == "number" ? type.timeout : jQuery.timeout;
|
|
||||||
ifModified = type.ifModified || false;
|
|
||||||
data = type.data;
|
|
||||||
url = type.url;
|
|
||||||
type = type.type;
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// Watch for a new set of requests
|
// Watch for a new set of requests
|
||||||
if ( s.global && ! jQuery.active++ )
|
if ( s.global && ! jQuery.active++ )
|
||||||
|
Loading…
Reference in New Issue
Block a user