2012-11-26 02:31:19 +00:00
module ( "ajax" , {
setup : function ( ) {
var jsonpCallback = this . jsonpCallback = jQuery . ajaxSettings . jsonpCallback ;
jQuery . ajaxSettings . jsonpCallback = function ( ) {
2012-11-03 04:06:50 +00:00
var callback = jsonpCallback . apply ( this , arguments ) ;
2012-11-26 02:31:19 +00:00
Globals . register ( callback ) ;
2012-11-03 04:06:50 +00:00
return callback ;
} ;
2012-11-26 02:31:19 +00:00
} ,
2012-12-01 20:25:52 +00:00
teardown : function ( ) {
jQuery ( document ) . off ( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" ) ;
2012-12-02 15:48:26 +00:00
moduleTeardown . apply ( this , arguments ) ;
2012-12-01 20:25:52 +00:00
}
2012-11-26 02:31:19 +00:00
} ) ;
2012-11-03 04:06:50 +00:00
2012-11-26 02:31:19 +00:00
( function ( ) {
2014-06-14 16:31:08 +00:00
test ( "Unit Testing Environment" , 2 , function ( ) {
ok ( hasPHP , "Running in an environment with PHP support. The AJAX tests only run if the environment supports PHP!" ) ;
ok ( ! isLocal , "Unit tests are not ran from file:// (especially in Chrome. If you must test from file:// with Chrome, run it with the --allow-file-access-from-files flag!)" ) ;
} ) ;
2012-11-03 04:06:50 +00:00
if ( ! jQuery . ajax || ( isLocal && ! hasPHP ) ) {
return ;
}
2007-09-03 23:45:14 +00:00
2012-12-02 15:48:26 +00:00
function addGlobalEvents ( expected ) {
return function ( ) {
expected = expected || "" ;
jQuery ( document ) . on ( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" , function ( e ) {
ok ( expected . indexOf ( e . type ) !== - 1 , e . type ) ;
} ) ;
} ;
2012-12-01 20:25:52 +00:00
}
2012-11-26 02:31:19 +00:00
//----------- jQuery.ajax()
2010-12-09 18:34:28 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - success callbacks" , 8 , {
2012-12-02 15:48:26 +00:00
setup : addGlobalEvents ( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess" ) ,
2012-12-05 13:54:14 +00:00
url : url ( "data/name.html" ) ,
2012-11-26 02:31:19 +00:00
beforeSend : function ( ) {
ok ( true , "beforeSend" ) ;
} ,
success : function ( ) {
ok ( true , "success" ) ;
} ,
complete : function ( ) {
ok ( true , "complete" ) ;
}
} ) ;
2010-12-09 18:34:28 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - success callbacks - (url, options) syntax" , 8 , {
2012-12-02 15:48:26 +00:00
setup : addGlobalEvents ( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess" ) ,
2012-11-26 02:31:19 +00:00
create : function ( options ) {
2012-12-05 13:54:14 +00:00
return jQuery . ajax ( url ( "data/name.html" ) , options ) ;
2012-11-26 02:31:19 +00:00
} ,
beforeSend : function ( ) {
ok ( true , "beforeSend" ) ;
} ,
success : function ( ) {
ok ( true , "success" ) ;
} ,
complete : function ( ) {
ok ( true , "complete" ) ;
}
2012-10-15 19:53:39 +00:00
} ) ;
2010-12-09 18:34:28 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - success callbacks (late binding)" , 8 , {
2012-12-02 15:48:26 +00:00
setup : addGlobalEvents ( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess" ) ,
2012-12-05 13:54:14 +00:00
url : url ( "data/name.html" ) ,
2012-11-26 02:31:19 +00:00
beforeSend : function ( ) {
ok ( true , "beforeSend" ) ;
} ,
success : true ,
afterSend : function ( request ) {
request . complete ( function ( ) {
2012-10-15 19:53:39 +00:00
ok ( true , "complete" ) ;
} ) . success ( function ( ) {
ok ( true , "success" ) ;
} ) . error ( function ( ) {
ok ( false , "error" ) ;
} ) ;
2012-11-26 02:31:19 +00:00
}
2012-10-15 19:53:39 +00:00
} ) ;
2010-12-09 18:34:28 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - success callbacks (oncomplete binding)" , 8 , {
2012-12-02 15:48:26 +00:00
setup : addGlobalEvents ( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess" ) ,
2012-12-05 13:54:14 +00:00
url : url ( "data/name.html" ) ,
2012-11-26 02:31:19 +00:00
beforeSend : function ( ) {
ok ( true , "beforeSend" ) ;
} ,
success : true ,
complete : function ( xhr ) {
xhr . complete ( function ( ) {
ok ( true , "complete" ) ;
} ) . success ( function ( ) {
ok ( true , "success" ) ;
} ) . error ( function ( ) {
ok ( false , "error" ) ;
2012-10-15 19:53:39 +00:00
} ) ;
2012-11-26 02:31:19 +00:00
}
2012-10-15 19:53:39 +00:00
} ) ;
2010-12-30 06:34:48 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - error callbacks" , 8 , {
2012-12-02 15:48:26 +00:00
setup : addGlobalEvents ( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError" ) ,
2012-12-05 13:54:14 +00:00
url : url ( "data/name.php?wait=5" ) ,
2012-11-26 02:31:19 +00:00
beforeSend : function ( ) {
ok ( true , "beforeSend" ) ;
} ,
2012-12-05 13:54:14 +00:00
afterSend : function ( request ) {
request . abort ( ) ;
} ,
2012-11-26 02:31:19 +00:00
error : function ( ) {
ok ( true , "error" ) ;
} ,
complete : function ( ) {
ok ( true , "complete" ) ;
2011-01-09 05:19:27 +00:00
}
2012-11-26 02:31:19 +00:00
} ) ;
2011-01-09 05:19:27 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - textStatus and errorThrown values" , 4 , [
2012-11-26 02:31:19 +00:00
{
2012-12-05 13:54:14 +00:00
url : url ( "data/name.php?wait=5" ) ,
2012-10-15 19:53:39 +00:00
error : function ( _ , textStatus , errorThrown ) {
strictEqual ( textStatus , "abort" , "textStatus is 'abort' for abort" ) ;
strictEqual ( errorThrown , "abort" , "errorThrown is 'abort' for abort" ) ;
2012-11-26 02:31:19 +00:00
} ,
afterSend : function ( request ) {
request . abort ( ) ;
2012-10-15 19:53:39 +00:00
}
2012-11-26 02:31:19 +00:00
} ,
{
2012-12-05 13:54:14 +00:00
url : url ( "data/name.php?wait=5" ) ,
2012-10-15 19:53:39 +00:00
error : function ( _ , textStatus , errorThrown ) {
strictEqual ( textStatus , "mystatus" , "textStatus is 'mystatus' for abort('mystatus')" ) ;
strictEqual ( errorThrown , "mystatus" , "errorThrown is 'mystatus' for abort('mystatus')" ) ;
} ,
2012-11-26 02:31:19 +00:00
afterSend : function ( request ) {
request . abort ( "mystatus" ) ;
2011-02-17 16:03:09 +00:00
}
2012-11-26 02:31:19 +00:00
}
] ) ;
2011-01-11 22:01:18 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - responseText on error" , 1 , {
url : url ( "data/errorWithText.php" ) ,
2012-11-26 02:31:19 +00:00
error : function ( xhr ) {
strictEqual ( xhr . responseText , "plain text message" , "Test jqXHR.responseText is filled for HTTP errors" ) ;
}
} ) ;
2011-01-11 22:01:18 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "jQuery.ajax() - retry with jQuery.ajax( this )" , 2 , function ( ) {
2012-10-15 19:53:39 +00:00
var previousUrl ,
firstTime = true ;
jQuery . ajax ( {
2012-12-05 13:54:14 +00:00
url : url ( "data/errorWithText.php" ) ,
2012-10-15 19:53:39 +00:00
error : function ( ) {
if ( firstTime ) {
firstTime = false ;
jQuery . ajax ( this ) ;
} else {
ok ( true , "Test retrying with jQuery.ajax(this) works" ) ;
jQuery . ajax ( {
2012-12-05 13:54:14 +00:00
url : url ( "data/errorWithText.php" ) ,
2012-10-15 19:53:39 +00:00
data : {
"x" : 1
} ,
beforeSend : function ( ) {
if ( ! previousUrl ) {
previousUrl = this . url ;
} else {
strictEqual ( this . url , previousUrl , "url parameters are not re-appended" ) ;
start ( ) ;
return false ;
}
} ,
error : function ( ) {
jQuery . ajax ( this ) ;
}
} ) ;
}
}
} ) ;
2011-01-11 22:01:18 +00:00
} ) ;
2013-11-11 02:28:36 +00:00
ajaxTest ( "jQuery.ajax() - headers" , 5 , {
2012-11-26 02:31:19 +00:00
setup : function ( ) {
2012-12-01 20:25:52 +00:00
jQuery ( document ) . ajaxSend ( function ( evt , xhr ) {
2012-11-26 02:31:19 +00:00
xhr . setRequestHeader ( "ajax-send" , "test" ) ;
} ) ;
} ,
2013-11-11 02:28:36 +00:00
url : url ( "data/headers.php?keys=siMPle_SometHing-elsE_OthEr_Nullable_undefined_Empty_ajax-send" ) ,
2012-11-26 02:31:19 +00:00
headers : {
"siMPle" : "value" ,
"SometHing-elsE" : "other value" ,
2013-11-11 02:28:36 +00:00
"OthEr" : "something else" ,
"Nullable" : null ,
2013-11-15 05:18:46 +00:00
"undefined" : undefined
2013-11-11 02:28:36 +00:00
// Support: Firefox
// Not all browsers allow empty-string headers
// https://bugzilla.mozilla.org/show_bug.cgi?id=815299
//"Empty": ""
2012-11-26 02:31:19 +00:00
} ,
success : function ( data , _ , xhr ) {
var i , emptyHeader ,
requestHeaders = jQuery . extend ( this . headers , {
"ajax-send" : "test"
} ) ,
tmp = [ ] ;
for ( i in requestHeaders ) {
2013-11-11 02:28:36 +00:00
tmp . push ( i , ": " , requestHeaders [ i ] + "" , "\n" ) ;
2012-11-26 02:31:19 +00:00
}
tmp = tmp . join ( "" ) ;
2013-03-13 23:23:36 +00:00
2012-11-26 02:31:19 +00:00
strictEqual ( data , tmp , "Headers were sent" ) ;
2012-12-05 13:54:14 +00:00
strictEqual ( xhr . getResponseHeader ( "Sample-Header" ) , "Hello World" , "Sample header received" ) ;
2013-11-11 02:28:36 +00:00
ok ( data . indexOf ( "undefined" ) < 0 , "Undefined header value was not sent" ) ;
2012-12-05 13:54:14 +00:00
emptyHeader = xhr . getResponseHeader ( "Empty-Header" ) ;
2012-11-26 02:31:19 +00:00
if ( emptyHeader === null ) {
ok ( true , "Firefox doesn't support empty headers" ) ;
} else {
strictEqual ( emptyHeader , "" , "Empty header received" ) ;
}
2012-12-05 13:54:14 +00:00
strictEqual ( xhr . getResponseHeader ( "Sample-Header2" ) , "Hello World 2" , "Second sample header received" ) ;
2011-01-09 03:28:42 +00:00
}
2012-11-26 02:31:19 +00:00
} ) ;
2011-01-09 03:28:42 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - Accept header" , 1 , {
url : url ( "data/headers.php?keys=accept" ) ,
2012-11-26 02:31:19 +00:00
headers : {
Accept : "very wrong accept value"
} ,
beforeSend : function ( xhr ) {
xhr . setRequestHeader ( "Accept" , "*/*" ) ;
} ,
success : function ( data ) {
strictEqual ( data , "accept: */*\n" , "Test Accept header is set to last value provided" ) ;
}
} ) ;
2011-01-09 03:28:42 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - contentType" , 2 , [
2012-11-26 02:31:19 +00:00
{
2012-12-05 13:54:14 +00:00
url : url ( "data/headers.php?keys=content-type" ) ,
2012-10-15 19:53:39 +00:00
contentType : "test" ,
success : function ( data ) {
2012-12-05 13:54:14 +00:00
strictEqual ( data , "content-type: test\n" , "Test content-type is sent when options.contentType is set" ) ;
2012-10-15 19:53:39 +00:00
}
2012-11-26 02:31:19 +00:00
} ,
{
2012-12-05 13:54:14 +00:00
url : url ( "data/headers.php?keys=content-type" ) ,
2012-10-15 19:53:39 +00:00
contentType : false ,
success : function ( data ) {
2013-11-15 04:50:53 +00:00
// Some server/interpreter combinations always supply a Content-Type to scripts
data = data || "content-type: \n" ;
strictEqual ( data , "content-type: \n" , "Test content-type is not set when options.contentType===false" ) ;
2012-10-15 19:53:39 +00:00
}
2012-11-26 02:31:19 +00:00
}
] ) ;
2011-03-15 18:20:03 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - protocol-less urls" , 1 , {
2012-11-26 02:31:19 +00:00
url : "//somedomain.com" ,
beforeSend : function ( xhr , settings ) {
equal ( settings . url , location . protocol + "//somedomain.com" , "Make sure that the protocol is added." ) ;
return false ;
} ,
error : true
2011-01-09 16:27:29 +00:00
} ) ;
2011-01-09 15:50:13 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - hash" , 3 , [
2012-11-26 02:31:19 +00:00
{
2012-12-05 13:54:14 +00:00
url : "data/name.html#foo" ,
2012-10-15 19:53:39 +00:00
beforeSend : function ( xhr , settings ) {
2012-12-05 13:54:14 +00:00
equal ( settings . url , "data/name.html" , "Make sure that the URL is trimmed." ) ;
2012-10-15 19:53:39 +00:00
return false ;
2012-11-26 02:31:19 +00:00
} ,
error : true
} ,
{
2012-12-05 13:54:14 +00:00
url : "data/name.html?abc#foo" ,
2012-10-15 19:53:39 +00:00
beforeSend : function ( xhr , settings ) {
2012-12-05 13:54:14 +00:00
equal ( settings . url , "data/name.html?abc" , "Make sure that the URL is trimmed." ) ;
2012-10-15 19:53:39 +00:00
return false ;
2012-11-26 02:31:19 +00:00
} ,
error : true
} ,
{
2012-12-05 13:54:14 +00:00
url : "data/name.html?abc#foo" ,
2012-10-15 19:53:39 +00:00
data : {
"test" : 123
} ,
beforeSend : function ( xhr , settings ) {
2012-12-05 13:54:14 +00:00
equal ( settings . url , "data/name.html?abc&test=123" , "Make sure that the URL is trimmed." ) ;
2012-10-15 19:53:39 +00:00
return false ;
2012-11-26 02:31:19 +00:00
} ,
error : true
}
] ) ;
2010-01-06 17:13:56 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - cross-domain detection" , 7 , function ( ) {
2012-11-26 02:31:19 +00:00
function request ( url , title , crossDomainOrOptions ) {
return jQuery . extend ( {
dataType : "jsonp" ,
url : url ,
beforeSend : function ( _ , s ) {
ok ( crossDomainOrOptions === false ? ! s . crossDomain : s . crossDomain , title ) ;
return false ;
} ,
error : true
} , crossDomainOrOptions ) ;
}
2010-11-06 18:52:30 +00:00
2012-10-15 19:53:39 +00:00
var loc = document . location ,
samePort = loc . port || ( loc . protocol === "http:" ? 80 : 443 ) ,
otherPort = loc . port === 666 ? 667 : 666 ,
otherProtocol = loc . protocol === "http:" ? "https:" : "http:" ;
2013-03-13 23:23:36 +00:00
2012-11-26 02:31:19 +00:00
return [
request (
loc . protocol + "//" + loc . host + ":" + samePort ,
"Test matching ports are not detected as cross-domain" ,
false
) ,
request (
otherProtocol + "//" + loc . host ,
"Test different protocols are detected as cross-domain"
) ,
request (
"app:/path" ,
"Adobe AIR app:/ URL detected as cross-domain"
) ,
request (
loc . protocol + "//example.invalid:" + ( loc . port || 80 ) ,
"Test different hostnames are detected as cross-domain"
) ,
request (
loc . protocol + "//" + loc . hostname + ":" + otherPort ,
"Test different ports are detected as cross-domain"
) ,
request (
"about:blank" ,
"Test about:blank is detected as cross-domain"
) ,
request (
loc . protocol + "//" + loc . host ,
"Test forced crossDomain is detected as cross-domain" ,
{
crossDomain : true
}
)
] ;
2009-09-15 15:19:58 +00:00
} ) ;
2012-12-01 20:25:52 +00:00
ajaxTest ( "jQuery.ajax() - abort" , 9 , {
2012-12-02 15:48:26 +00:00
setup : addGlobalEvents ( "ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete" ) ,
2012-12-05 13:54:14 +00:00
url : url ( "data/name.php?wait=5" ) ,
2012-11-26 02:31:19 +00:00
beforeSend : function ( ) {
ok ( true , "beforeSend" ) ;
} ,
afterSend : function ( xhr ) {
strictEqual ( xhr . readyState , 1 , "XHR readyState indicates successful dispatch" ) ;
xhr . abort ( ) ;
strictEqual ( xhr . readyState , 0 , "XHR readyState indicates successful abortion" ) ;
} ,
error : true ,
complete : function ( ) {
2012-10-15 19:53:39 +00:00
ok ( true , "complete" ) ;
2012-11-26 02:31:19 +00:00
}
2011-01-20 03:12:15 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - events with context" , 12 , function ( ) {
2011-01-20 03:12:15 +00:00
2012-12-05 13:54:14 +00:00
var context = document . createElement ( "div" ) ;
2011-01-20 03:12:15 +00:00
2012-10-15 19:53:39 +00:00
function event ( e ) {
2012-12-05 13:54:14 +00:00
equal ( this , context , e . type ) ;
2009-05-01 00:59:27 +00:00
}
2007-09-03 23:45:14 +00:00
2012-10-15 19:53:39 +00:00
function callback ( msg ) {
return function ( ) {
2012-12-05 13:54:14 +00:00
equal ( this , context , "context is preserved on callback " + msg ) ;
2012-10-15 19:53:39 +00:00
} ;
2012-05-18 17:28:50 +00:00
}
2007-09-03 23:45:14 +00:00
2012-11-26 02:31:19 +00:00
return {
setup : function ( ) {
2012-12-05 13:54:14 +00:00
jQuery ( context ) . appendTo ( "#foo" )
. ajaxSend ( event )
. ajaxComplete ( event )
. ajaxError ( event )
. ajaxSuccess ( event ) ;
2012-11-26 02:31:19 +00:00
} ,
requests : [ {
2012-12-05 13:54:14 +00:00
url : url ( "data/name.html" ) ,
context : context ,
2012-11-26 02:31:19 +00:00
beforeSend : callback ( "beforeSend" ) ,
success : callback ( "success" ) ,
complete : callback ( "complete" )
} , {
2012-12-05 13:54:14 +00:00
url : url ( "data/404.html" ) ,
context : context ,
2012-11-26 02:31:19 +00:00
beforeSend : callback ( "beforeSend" ) ,
error : callback ( "error" ) ,
complete : callback ( "complete" )
} ]
} ;
} ) ;
2013-03-13 23:23:36 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - events without context" , 3 , function ( ) {
2012-10-15 19:53:39 +00:00
function nocallback ( msg ) {
return function ( ) {
2012-12-05 13:54:14 +00:00
equal ( typeof this . url , "string" , "context is settings on callback " + msg ) ;
2012-10-15 19:53:39 +00:00
} ;
2012-05-18 17:28:50 +00:00
}
2012-11-26 02:31:19 +00:00
return {
2012-12-05 13:54:14 +00:00
url : url ( "data/404.html" ) ,
2012-11-26 02:31:19 +00:00
beforeSend : nocallback ( "beforeSend" ) ,
error : nocallback ( "error" ) ,
complete : nocallback ( "complete" )
} ;
} ) ;
2010-12-09 18:34:28 +00:00
2014-05-30 13:48:43 +00:00
ajaxTest ( "#15118 - jQuery.ajax() - function without jQuery.event" , 1 , function ( ) {
var holder ;
return {
url : url ( "data/json.php" ) ,
setup : function ( ) {
holder = jQuery . event ;
delete jQuery . event ;
} ,
complete : function ( ) {
ok ( true , "Call can be made without jQuery.event" ) ;
jQuery . event = holder ;
} ,
success : true
} ;
} ) ;
2014-07-13 17:53:00 +00:00
ajaxTest ( "#15160 - jQuery.ajax() - request manually aborted in ajaxSend" , 3 , {
setup : function ( ) {
jQuery ( document ) . on ( "ajaxSend" , function ( e , jqXHR ) {
jqXHR . abort ( ) ;
} ) ;
jQuery ( document ) . on ( "ajaxError ajaxComplete" , function ( e , jqXHR ) {
equal ( jqXHR . statusText , "abort" , "jqXHR.statusText equals abort on global ajaxComplete and ajaxError events" ) ;
} ) ;
} ,
url : url ( "data/name.html" ) ,
error : true ,
complete : function ( ) {
ok ( true , "complete" ) ;
}
} ) ;
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - context modification" , 1 , {
url : url ( "data/name.html" ) ,
2012-11-26 02:31:19 +00:00
context : { } ,
beforeSend : function ( ) {
this . test = "foo" ;
} ,
afterSend : function ( ) {
strictEqual ( this . context . test , "foo" , "Make sure the original object is maintained." ) ;
} ,
2012-12-05 13:54:14 +00:00
success : true
2012-11-26 02:31:19 +00:00
} ) ;
2012-10-15 19:53:39 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - context modification through ajaxSetup" , 3 , function ( ) {
2012-11-26 02:31:19 +00:00
var obj = { } ;
return {
setup : function ( ) {
jQuery . ajaxSetup ( {
context : obj
2012-10-15 19:53:39 +00:00
} ) ;
2012-11-26 02:31:19 +00:00
strictEqual ( jQuery . ajaxSettings . context , obj , "Make sure the context is properly set in ajaxSettings." ) ;
2012-10-15 19:53:39 +00:00
} ,
2012-11-26 02:31:19 +00:00
requests : [ {
2012-12-05 13:54:14 +00:00
url : url ( "data/name.html" ) ,
success : function ( ) {
2012-11-26 02:31:19 +00:00
strictEqual ( this , obj , "Make sure the original object is maintained." ) ;
}
} , {
2012-12-05 13:54:14 +00:00
url : url ( "data/name.html" ) ,
2012-11-26 02:31:19 +00:00
context : { } ,
2012-12-05 13:54:14 +00:00
success : function ( ) {
2013-02-27 20:44:34 +00:00
ok ( this !== obj , "Make sure overriding context is possible." ) ;
2012-11-26 02:31:19 +00:00
}
} ]
} ;
2010-10-23 17:23:51 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - disabled globals" , 3 , {
2012-12-02 15:53:34 +00:00
setup : addGlobalEvents ( "" ) ,
2012-11-26 02:31:19 +00:00
global : false ,
2012-12-05 13:54:14 +00:00
url : url ( "data/name.html" ) ,
2012-11-26 02:31:19 +00:00
beforeSend : function ( ) {
ok ( true , "beforeSend" ) ;
} ,
success : function ( ) {
ok ( true , "success" ) ;
} ,
complete : function ( ) {
ok ( true , "complete" ) ;
}
} ) ;
2009-05-01 00:59:27 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements" , 3 , {
url : url ( "data/with_fries.xml" ) ,
dataType : "xml" ,
2012-11-26 02:31:19 +00:00
success : function ( resp ) {
2012-12-05 13:54:14 +00:00
equal ( jQuery ( "properties" , resp ) . length , 1 , "properties in responseXML" ) ;
equal ( jQuery ( "jsconf" , resp ) . length , 1 , "jsconf in responseXML" ) ;
equal ( jQuery ( "thing" , resp ) . length , 2 , "things in responseXML" ) ;
2012-11-26 02:31:19 +00:00
}
} ) ;
2009-05-01 00:59:27 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements (over JSONP)" , 3 , {
url : url ( "data/with_fries_over_jsonp.php" ) ,
2012-11-26 02:31:19 +00:00
dataType : "jsonp xml" ,
success : function ( resp ) {
2012-12-05 13:54:14 +00:00
equal ( jQuery ( "properties" , resp ) . length , 1 , "properties in responseXML" ) ;
equal ( jQuery ( "jsconf" , resp ) . length , 1 , "jsconf in responseXML" ) ;
equal ( jQuery ( "thing" , resp ) . length , 2 , "things in responseXML" ) ;
2012-11-26 02:31:19 +00:00
}
} ) ;
2009-05-01 00:59:27 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - HEAD requests" , 2 , [
{
url : url ( "data/name.html" ) ,
type : "HEAD" ,
success : function ( data , status , xhr ) {
ok ( /Date/i . test ( xhr . getAllResponseHeaders ( ) ) , "No Date in HEAD response" ) ;
}
2012-11-26 02:31:19 +00:00
} ,
2012-12-05 13:54:14 +00:00
{
url : url ( "data/name.html" ) ,
data : {
"whip_it" : "good"
} ,
type : "HEAD" ,
success : function ( data , status , xhr ) {
ok ( /Date/i . test ( xhr . getAllResponseHeaders ( ) ) , "No Date in HEAD response with data" ) ;
}
2012-12-04 06:39:27 +00:00
}
2012-12-05 13:54:14 +00:00
] ) ;
2007-09-03 23:45:14 +00:00
2012-11-26 02:31:19 +00:00
ajaxTest ( "jQuery.ajax() - beforeSend" , 1 , {
2012-12-05 13:54:14 +00:00
url : url ( "data/name.html" ) ,
2013-04-09 15:45:09 +00:00
beforeSend : function ( ) {
2012-11-26 02:31:19 +00:00
this . check = true ;
} ,
2013-04-09 15:45:09 +00:00
success : function ( ) {
2012-11-26 02:31:19 +00:00
ok ( this . check , "check beforeSend was executed" ) ;
}
2008-04-22 22:07:17 +00:00
} ) ;
2012-11-26 02:31:19 +00:00
ajaxTest ( "jQuery.ajax() - beforeSend, cancel request manually" , 2 , {
create : function ( ) {
return jQuery . ajax ( {
2012-12-05 13:54:14 +00:00
url : url ( "data/name.html" ) ,
2012-11-26 02:31:19 +00:00
beforeSend : function ( xhr ) {
ok ( true , "beforeSend got called, canceling" ) ;
xhr . abort ( ) ;
} ,
success : function ( ) {
ok ( false , "request didn't get canceled" ) ;
} ,
complete : function ( ) {
ok ( false , "request didn't get canceled" ) ;
} ,
error : function ( ) {
ok ( false , "request didn't get canceled" ) ;
}
} ) ;
} ,
fail : function ( _ , reason ) {
2012-10-15 19:53:39 +00:00
strictEqual ( reason , "canceled" , "canceled request must fail with 'canceled' status text" ) ;
2012-11-26 02:31:19 +00:00
}
2007-08-25 03:55:12 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - dataType html" , 5 , {
2012-11-26 02:31:19 +00:00
setup : function ( ) {
Globals . register ( "testFoo" ) ;
2012-12-03 04:32:16 +00:00
Globals . register ( "testBar" ) ;
2012-11-26 02:31:19 +00:00
} ,
dataType : "html" ,
2012-12-05 13:54:14 +00:00
url : url ( "data/test.html" ) ,
2012-11-26 02:31:19 +00:00
success : function ( data ) {
ok ( data . match ( /^html text/ ) , "Check content for datatype html" ) ;
jQuery ( "#ap" ) . html ( data ) ;
strictEqual ( window [ "testFoo" ] , "foo" , "Check if script was evaluated for datatype html" ) ;
2012-12-03 04:32:16 +00:00
strictEqual ( window [ "testBar" ] , "bar" , "Check if script src was evaluated for datatype html" ) ;
2012-11-26 02:31:19 +00:00
}
2006-11-18 13:37:01 +00:00
} ) ;
2012-11-26 02:31:19 +00:00
ajaxTest ( "jQuery.ajax() - synchronous request" , 1 , {
2012-12-05 13:54:14 +00:00
url : url ( "data/json_obj.js" ) ,
2012-11-26 02:31:19 +00:00
dataType : "text" ,
async : false ,
success : true ,
afterSend : function ( xhr ) {
2012-12-05 13:54:14 +00:00
ok ( /^\{ "data"/ . test ( xhr . responseText ) , "check returned text" ) ;
2012-11-26 02:31:19 +00:00
}
2006-12-31 15:44:59 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - synchronous request with callbacks" , 2 , {
url : url ( "data/json_obj.js" ) ,
2012-11-26 02:31:19 +00:00
async : false ,
dataType : "text" ,
success : true ,
afterSend : function ( xhr ) {
var result ;
xhr . done ( function ( data ) {
ok ( true , "success callback executed" ) ;
2012-10-15 19:53:39 +00:00
result = data ;
2012-11-26 02:31:19 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
ok ( /^\{ "data"/ . test ( result ) , "check returned text" ) ;
2012-11-26 02:31:19 +00:00
}
2011-01-11 19:02:33 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
asyncTest ( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object" , 8 , function ( ) {
2013-04-09 15:45:09 +00:00
var target = "data/name.html" ,
successCount = 0 ,
errorCount = 0 ,
errorEx = "" ,
success = function ( ) {
successCount ++ ;
} ;
jQuery ( document ) . on ( "ajaxError.passthru" , function ( e , xml ) {
2012-10-15 19:53:39 +00:00
errorCount ++ ;
2012-12-05 13:54:14 +00:00
errorEx += ": " + xml . status ;
2012-10-15 19:53:39 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
jQuery ( document ) . one ( "ajaxStop" , function ( ) {
equal ( successCount , 5 , "Check all ajax calls successful" ) ;
equal ( errorCount , 0 , "Check no ajax errors (status" + errorEx + ")" ) ;
jQuery ( document ) . off ( "ajaxError.passthru" ) ;
2012-10-15 19:53:39 +00:00
start ( ) ;
} ) ;
2012-12-05 13:54:14 +00:00
Globals . register ( "testBar" ) ;
2009-05-01 00:59:27 +00:00
2012-12-05 13:54:14 +00:00
ok ( jQuery . get ( url ( target ) , success ) , "get" ) ;
ok ( jQuery . post ( url ( target ) , success ) , "post" ) ;
2014-04-04 18:31:38 +00:00
ok ( jQuery . getScript ( url ( "data/testbar.php" ) , success ) , "script" ) ;
2012-12-05 13:54:14 +00:00
ok ( jQuery . getJSON ( url ( "data/json_obj.js" ) , success ) , "json" ) ;
2012-10-15 19:53:39 +00:00
ok ( jQuery . ajax ( {
2012-12-05 13:54:14 +00:00
url : url ( target ) ,
2012-10-15 19:53:39 +00:00
success : success
} ) , "generic" ) ;
2008-05-27 22:46:28 +00:00
} ) ;
2012-11-26 02:31:19 +00:00
ajaxTest ( "jQuery.ajax() - cache" , 12 , function ( ) {
2013-03-13 23:23:36 +00:00
2012-11-26 02:31:19 +00:00
var re = /_=(.*?)(&|$)/g ;
2013-03-13 23:23:36 +00:00
2012-11-26 02:31:19 +00:00
function request ( url , title ) {
return {
url : url ,
cache : false ,
beforeSend : function ( ) {
var parameter , tmp ;
while ( ( tmp = re . exec ( this . url ) ) ) {
strictEqual ( parameter , undefined , title + ": only one 'no-cache' parameter" ) ;
parameter = tmp [ 1 ] ;
notStrictEqual ( parameter , "tobereplaced555" , title + ": parameter (if it was there) was replaced" ) ;
}
return false ;
} ,
error : true
2012-10-15 19:53:39 +00:00
} ;
2012-11-26 02:31:19 +00:00
}
2013-03-13 23:23:36 +00:00
2012-11-26 02:31:19 +00:00
return [
request (
2012-12-05 13:54:14 +00:00
"data/text.php" ,
2012-11-26 02:31:19 +00:00
"no parameter"
) ,
request (
2012-12-05 13:54:14 +00:00
"data/text.php?pizza=true" ,
2012-11-26 02:31:19 +00:00
"1 parameter"
) ,
request (
2012-12-05 13:54:14 +00:00
"data/text.php?_=tobereplaced555" ,
2012-11-26 02:31:19 +00:00
"_= parameter"
) ,
request (
2012-12-05 13:54:14 +00:00
"data/text.php?pizza=true&_=tobereplaced555" ,
2012-11-26 02:31:19 +00:00
"1 parameter and _="
) ,
request (
2012-12-05 13:54:14 +00:00
"data/text.php?_=tobereplaced555&tv=false" ,
2012-11-26 02:31:19 +00:00
"_= and 1 parameter"
) ,
request (
2012-12-05 13:54:14 +00:00
"data/text.php?name=David&_=tobereplaced555&washere=true" ,
2012-11-26 02:31:19 +00:00
"2 parameters surrounding _="
)
] ;
2012-05-02 00:22:56 +00:00
} ) ;
2012-11-26 02:31:19 +00:00
jQuery . each ( [ " - Same Domain" , " - Cross Domain" ] , function ( crossDomain , label ) {
2012-10-15 19:53:39 +00:00
2012-11-26 02:31:19 +00:00
ajaxTest ( "jQuery.ajax() - JSONP - Query String (?n)" + label , 4 , [
2012-12-05 13:54:14 +00:00
{
url : "data/jsonp.php?callback=?" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
success : function ( data ) {
ok ( data . data , "JSON results returned (GET, url callback)" ) ;
2012-11-26 02:31:19 +00:00
}
2012-12-05 13:54:14 +00:00
} ,
{
url : "data/jsonp.php?callback=??" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
success : function ( data ) {
ok ( data . data , "JSON results returned (GET, url context-free callback)" ) ;
}
} ,
{
url : "data/jsonp.php/??" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
success : function ( data ) {
ok ( data . data , "JSON results returned (GET, REST-like)" ) ;
}
} ,
{
url : "data/jsonp.php/???json=1" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
success : function ( data ) {
strictEqual ( jQuery . type ( data ) , "array" , "JSON results returned (GET, REST-like with param)" ) ;
}
}
2012-11-26 02:31:19 +00:00
] ) ;
2007-08-19 23:37:26 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - JSONP - Explicit callback param" + label , 9 , {
2012-11-26 02:31:19 +00:00
setup : function ( ) {
Globals . register ( "functionToCleanUp" ) ;
Globals . register ( "XXX" ) ;
Globals . register ( "jsonpResults" ) ;
window [ "jsonpResults" ] = function ( data ) {
2012-12-05 13:54:14 +00:00
ok ( data [ "data" ] , "JSON results returned (GET, custom callback function)" ) ;
2012-11-26 02:31:19 +00:00
} ;
2011-01-16 04:27:16 +00:00
} ,
2012-12-05 13:54:14 +00:00
requests : [ {
url : "data/jsonp.php" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
jsonp : "callback" ,
success : function ( data ) {
ok ( data [ "data" ] , "JSON results returned (GET, data obj callback)" ) ;
}
} , {
url : "data/jsonp.php" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
jsonpCallback : "jsonpResults" ,
success : function ( data ) {
ok ( data . data , "JSON results returned (GET, custom callback name)" ) ;
}
} , {
url : "data/jsonp.php" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
jsonpCallback : "functionToCleanUp" ,
success : function ( data ) {
ok ( data [ "data" ] , "JSON results returned (GET, custom callback name to be cleaned up)" ) ;
2014-02-18 17:50:42 +00:00
strictEqual ( window [ "functionToCleanUp" ] , true , "Callback was removed (GET, custom callback name to be cleaned up)" ) ;
2012-12-05 13:54:14 +00:00
var xhr ;
jQuery . ajax ( {
url : "data/jsonp.php" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
jsonpCallback : "functionToCleanUp" ,
beforeSend : function ( jqXHR ) {
xhr = jqXHR ;
return false ;
}
} ) ;
xhr . fail ( function ( ) {
ok ( true , "Ajax error JSON (GET, custom callback name to be cleaned up)" ) ;
2014-02-18 17:50:42 +00:00
strictEqual ( window [ "functionToCleanUp" ] , true , "Callback was removed after early abort (GET, custom callback name to be cleaned up)" ) ;
2012-12-05 13:54:14 +00:00
} ) ;
}
} , {
url : "data/jsonp.php?callback=XXX" ,
dataType : "jsonp" ,
jsonp : false ,
jsonpCallback : "XXX" ,
crossDomain : crossDomain ,
beforeSend : function ( ) {
ok ( /^data\/jsonp.php\?callback=XXX&_=\d+$/ . test ( this . url ) , "The URL wasn't messed with (GET, custom callback name with no url manipulation)" ) ;
} ,
success : function ( data ) {
ok ( data [ "data" ] , "JSON results returned (GET, custom callback name with no url manipulation)" ) ;
}
} ]
2012-10-15 19:53:39 +00:00
} ) ;
2007-11-29 19:07:20 +00:00
2012-11-26 02:31:19 +00:00
ajaxTest ( "jQuery.ajax() - JSONP - Callback in data" + label , 2 , [
2012-12-05 13:54:14 +00:00
{
url : "data/jsonp.php" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
data : "callback=?" ,
success : function ( data ) {
ok ( data . data , "JSON results returned (GET, data callback)" ) ;
}
} ,
{
url : "data/jsonp.php" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
data : "callback=??" ,
success : function ( data ) {
ok ( data . data , "JSON results returned (GET, data context-free callback)" ) ;
}
}
2012-11-26 02:31:19 +00:00
] ) ;
2007-09-15 01:18:30 +00:00
2006-11-18 13:37:01 +00:00
2012-11-26 02:31:19 +00:00
ajaxTest ( "jQuery.ajax() - JSONP - POST" + label , 3 , [
2012-12-05 13:54:14 +00:00
{
2012-12-05 13:54:00 +00:00
type : "POST" ,
2012-12-05 13:54:14 +00:00
url : "data/jsonp.php" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
success : function ( data ) {
ok ( data [ "data" ] , "JSON results returned (POST, no callback)" ) ;
}
} ,
{
2012-11-26 02:31:19 +00:00
type : "POST" ,
2012-12-05 13:54:14 +00:00
url : "data/jsonp.php" ,
data : "callback=?" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
success : function ( data ) {
ok ( data [ "data" ] , "JSON results returned (POST, data callback)" ) ;
}
} ,
{
2012-11-26 02:31:19 +00:00
type : "POST" ,
2012-12-05 13:54:14 +00:00
url : "data/jsonp.php" ,
jsonp : "callback" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
success : function ( data ) {
ok ( data [ "data" ] , "JSON results returned (POST, data obj callback)" ) ;
}
}
2012-11-26 02:31:19 +00:00
] ) ;
2009-05-01 00:59:27 +00:00
2012-11-26 02:31:19 +00:00
ajaxTest ( "jQuery.ajax() - JSONP" + label , 3 , [
2012-12-05 13:54:14 +00:00
{
url : "data/jsonp.php" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
success : function ( data ) {
ok ( data . data , "JSON results returned (GET, no callback)" ) ;
}
} ,
{
2012-11-26 02:31:19 +00:00
create : function ( options ) {
var request = jQuery . ajax ( options ) ,
promise = request . then ( function ( data ) {
2012-12-05 13:54:14 +00:00
ok ( data . data , "first request: JSON results returned (GET, no callback)" ) ;
request = jQuery . ajax ( this ) . done ( function ( data ) {
ok ( data . data , "this re-used: JSON results returned (GET, no callback)" ) ;
} ) ;
2012-11-26 02:31:19 +00:00
promise . abort = request . abort ;
return request ;
} ) ;
promise . abort = request . abort ;
return promise ;
2012-12-05 13:54:14 +00:00
} ,
url : "data/jsonp.php" ,
dataType : "jsonp" ,
crossDomain : crossDomain ,
success : true
}
2012-11-26 02:31:19 +00:00
] ) ;
2006-11-18 13:37:01 +00:00
2012-11-26 02:31:19 +00:00
} ) ;
2012-10-15 16:37:02 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - script, Remote" , 2 , {
setup : function ( ) {
Globals . register ( "testBar" ) ;
} ,
2014-04-04 18:31:38 +00:00
url : window . location . href . replace ( /[^\/]*$/ , "" ) + "data/testbar.php" ,
2012-12-05 13:54:14 +00:00
dataType : "script" ,
2013-04-09 15:45:09 +00:00
success : function ( ) {
2012-12-05 13:54:14 +00:00
strictEqual ( window [ "testBar" ] , "bar" , "Script results returned (GET, no callback)" ) ;
}
2012-11-26 02:31:19 +00:00
} ) ;
2006-11-18 13:37:01 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - script, Remote with POST" , 3 , {
setup : function ( ) {
Globals . register ( "testBar" ) ;
2012-12-04 06:39:27 +00:00
} ,
2014-04-04 18:31:38 +00:00
url : window . location . href . replace ( /[^\/]*$/ , "" ) + "data/testbar.php" ,
2012-12-05 13:54:14 +00:00
type : "POST" ,
dataType : "script" ,
success : function ( data , status ) {
strictEqual ( window [ "testBar" ] , "bar" , "Script results returned (POST, no callback)" ) ;
strictEqual ( status , "success" , "Script results returned (POST, no callback)" ) ;
}
} ) ;
ajaxTest ( "jQuery.ajax() - script, Remote with scheme-less URL" , 2 , {
setup : function ( ) {
Globals . register ( "testBar" ) ;
} ,
2014-04-04 18:31:38 +00:00
url : window . location . href . replace ( /[^\/]*$/ , "" ) . replace ( /^.*?\/\// , "//" ) + "data/testbar.php" ,
2012-12-05 13:54:14 +00:00
dataType : "script" ,
2013-04-09 15:45:09 +00:00
success : function ( ) {
2012-12-05 13:54:14 +00:00
strictEqual ( window [ "testBar" ] , "bar" , "Script results returned (GET, no callback)" ) ;
}
} ) ;
ajaxTest ( "jQuery.ajax() - malformed JSON" , 2 , {
url : "data/badjson.js" ,
2012-11-26 02:31:19 +00:00
dataType : "json" ,
error : function ( xhr , msg , detailedMsg ) {
strictEqual ( msg , "parsererror" , "A parse error occurred." ) ;
ok ( /(invalid|error|exception)/i . test ( detailedMsg ) , "Detailed parsererror message provided" ) ;
}
} ) ;
2006-11-18 13:37:01 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - script by content-type" , 2 , [
{
url : "data/script.php" ,
data : {
"header" : "script"
} ,
success : true
2012-11-26 02:31:19 +00:00
} ,
2012-12-05 13:54:14 +00:00
{
url : "data/script.php" ,
data : {
"header" : "ecma"
} ,
success : true
}
] ) ;
ajaxTest ( "jQuery.ajax() - JSON by content-type" , 5 , {
url : "data/json.php" ,
2012-11-26 02:31:19 +00:00
data : {
2012-12-05 13:54:14 +00:00
"header" : "json" ,
"json" : "array"
2012-11-26 02:31:19 +00:00
} ,
success : function ( json ) {
2012-12-05 13:54:14 +00:00
ok ( json . length >= 2 , "Check length" ) ;
strictEqual ( json [ 0 ] [ "name" ] , "John" , "Check JSON: first, name" ) ;
strictEqual ( json [ 0 ] [ "age" ] , 21 , "Check JSON: first, age" ) ;
strictEqual ( json [ 1 ] [ "name" ] , "Peter" , "Check JSON: second, name" ) ;
strictEqual ( json [ 1 ] [ "age" ] , 25 , "Check JSON: second, age" ) ;
2012-11-26 02:31:19 +00:00
}
2007-03-25 10:55:22 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - JSON by content-type disabled with options" , 6 , {
url : url ( "data/json.php" ) ,
2012-11-26 02:31:19 +00:00
data : {
2012-12-05 13:54:14 +00:00
"header" : "json" ,
"json" : "array"
2012-11-26 02:31:19 +00:00
} ,
contents : {
2012-12-05 13:54:14 +00:00
"json" : false
2012-11-26 02:31:19 +00:00
} ,
2012-12-05 13:54:14 +00:00
success : function ( text ) {
strictEqual ( typeof text , "string" , "json wasn't auto-determined" ) ;
var json = jQuery . parseJSON ( text ) ;
ok ( json . length >= 2 , "Check length" ) ;
strictEqual ( json [ 0 ] [ "name" ] , "John" , "Check JSON: first, name" ) ;
strictEqual ( json [ 0 ] [ "age" ] , 21 , "Check JSON: first, age" ) ;
strictEqual ( json [ 1 ] [ "name" ] , "Peter" , "Check JSON: second, name" ) ;
strictEqual ( json [ 1 ] [ "age" ] , 25 , "Check JSON: second, age" ) ;
2012-11-26 02:31:19 +00:00
}
2011-01-07 14:52:58 +00:00
} ) ;
2010-06-15 03:08:28 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - simple get" , 1 , {
type : "GET" ,
url : url ( "data/name.php?name=foo" ) ,
success : function ( msg ) {
strictEqual ( msg , "bar" , "Check for GET" ) ;
}
} ) ;
ajaxTest ( "jQuery.ajax() - simple post" , 1 , {
type : "POST" ,
url : url ( "data/name.php" ) ,
data : "name=peter" ,
success : function ( msg ) {
strictEqual ( msg , "pan" , "Check for POST" ) ;
}
} ) ;
ajaxTest ( "jQuery.ajax() - data option - empty bodies for non-GET requests" , 1 , {
url : "data/echoData.php" ,
data : undefined ,
type : "post" ,
success : function ( result ) {
strictEqual ( result , "" ) ;
2012-11-26 02:31:19 +00:00
}
2012-10-15 19:53:39 +00:00
} ) ;
2009-06-15 13:36:12 +00:00
2012-10-15 19:53:39 +00:00
var ifModifiedNow = new Date ( ) ;
2009-06-15 13:36:12 +00:00
2012-12-05 13:54:14 +00:00
jQuery . each (
/* jQuery.each arguments start */
{
" (cache)" : true ,
" (no cache)" : false
} ,
function ( label , cache ) {
var isOpera = ! ! window . opera ;
asyncTest ( "jQuery.ajax() - If-Modified-Since support" + label , 3 , function ( ) {
var url = "data/if_modified_since.php?ts=" + ifModifiedNow ++ ;
jQuery . ajax ( {
2011-01-31 18:59:53 +00:00
url : url ,
ifModified : true ,
2012-12-05 13:54:14 +00:00
cache : cache ,
success : function ( data , status ) {
strictEqual ( status , "success" ) ;
jQuery . ajax ( {
url : url ,
ifModified : true ,
cache : cache ,
success : function ( data , status ) {
if ( data === "FAIL" ) {
ok ( isOpera , "Opera is incapable of doing .setRequestHeader('If-Modified-Since')." ) ;
ok ( isOpera , "Opera is incapable of doing .setRequestHeader('If-Modified-Since')." ) ;
} else {
strictEqual ( status , "notmodified" ) ;
ok ( data == null , "response body should be empty" ) ;
}
start ( ) ;
} ,
error : function ( ) {
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
ok ( isOpera , "error" ) ;
ok ( isOpera , "error" ) ;
start ( ) ;
}
} ) ;
} ,
error : function ( ) {
strictEqual ( false , "error" ) ;
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
ok ( isOpera , "error" ) ;
start ( ) ;
}
2012-11-26 02:31:19 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
} ) ;
asyncTest ( "jQuery.ajax() - Etag support" + label , 3 , function ( ) {
var url = "data/etag.php?ts=" + ifModifiedNow ++ ;
jQuery . ajax ( {
url : url ,
ifModified : true ,
cache : cache ,
success : function ( data , status ) {
strictEqual ( status , "success" ) ;
jQuery . ajax ( {
url : url ,
ifModified : true ,
cache : cache ,
success : function ( data , status ) {
if ( data === "FAIL" ) {
ok ( isOpera , "Opera is incapable of doing .setRequestHeader('If-None-Match')." ) ;
ok ( isOpera , "Opera is incapable of doing .setRequestHeader('If-None-Match')." ) ;
} else {
strictEqual ( status , "notmodified" ) ;
ok ( data == null , "response body should be empty" ) ;
}
start ( ) ;
} ,
error : function ( ) {
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
ok ( isOpera , "error" ) ;
ok ( isOpera , "error" ) ;
start ( ) ;
}
} ) ;
} ,
error : function ( ) {
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
ok ( isOpera , "error" ) ;
start ( ) ;
2012-12-04 06:39:27 +00:00
}
2012-12-05 13:54:14 +00:00
} ) ;
2012-10-15 19:53:39 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
}
/* jQuery.each arguments end */
) ;
2010-12-09 18:34:28 +00:00
2012-11-26 02:31:19 +00:00
ajaxTest ( "jQuery.ajax() - failing cross-domain (non-existing)" , 1 , {
// see RFC 2606
url : "http://example.invalid" ,
error : function ( xhr , _ , e ) {
ok ( true , "file not found: " + xhr . status + " => " + e ) ;
2012-10-15 19:53:39 +00:00
}
2012-11-26 02:31:19 +00:00
} ) ;
2010-11-17 06:59:24 +00:00
2012-11-26 02:31:19 +00:00
ajaxTest ( "jQuery.ajax() - failing cross-domain" , 1 , {
url : "http://" + externalHost ,
error : function ( xhr , _ , e ) {
ok ( true , "access denied: " + xhr . status + " => " + e ) ;
}
2012-10-15 19:53:39 +00:00
} ) ;
2010-04-29 03:45:34 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - atom+xml" , 1 , {
url : url ( "data/atom+xml.php" ) ,
success : function ( ) {
ok ( true , "success" ) ;
}
} ) ;
asyncTest ( "jQuery.ajax() - statusText" , 3 , function ( ) {
jQuery . ajax ( url ( "data/statusText.php?status=200&text=Hello" ) ) . done ( function ( _ , statusText , jqXHR ) {
strictEqual ( statusText , "success" , "callback status text ok for success" ) ;
ok ( jqXHR . statusText === "Hello" || jqXHR . statusText === "OK" , "jqXHR status text ok for success (" + jqXHR . statusText + ")" ) ;
jQuery . ajax ( url ( "data/statusText.php?status=404&text=World" ) ) . fail ( function ( jqXHR , statusText ) {
2012-10-15 19:53:39 +00:00
strictEqual ( statusText , "error" , "callback status text ok for error" ) ;
2012-12-05 13:54:14 +00:00
// ok( jqXHR.statusText === "World" || jQuery.browser.safari && jqXHR.statusText === "Not Found", "jqXHR status text ok for error (" + jqXHR.statusText + ")" );
start ( ) ;
} ) ;
} ) ;
} ) ;
asyncTest ( "jQuery.ajax() - statusCode" , 20 , function ( ) {
var count = 12 ;
function countComplete ( ) {
if ( ! -- count ) {
start ( ) ;
2011-01-13 16:01:25 +00:00
}
2012-10-15 19:53:39 +00:00
}
2011-01-13 16:01:25 +00:00
2012-12-05 13:54:14 +00:00
function createStatusCodes ( name , isSuccess ) {
name = "Test " + name + " " + ( isSuccess ? "success" : "error" ) ;
2012-10-15 19:53:39 +00:00
return {
200 : function ( ) {
2012-12-05 13:54:14 +00:00
ok ( isSuccess , name ) ;
2012-10-15 19:53:39 +00:00
} ,
404 : function ( ) {
2012-12-05 13:54:14 +00:00
ok ( ! isSuccess , name ) ;
2012-10-15 19:53:39 +00:00
}
} ;
}
2012-12-05 13:54:14 +00:00
jQuery . each (
/* jQuery.each arguments start */
{
"data/name.html" : true ,
"data/someFileThatDoesNotExist.html" : false
} ,
function ( uri , isSuccess ) {
jQuery . ajax ( url ( uri ) , {
statusCode : createStatusCodes ( "in options" , isSuccess ) ,
complete : countComplete
} ) ;
jQuery . ajax ( url ( uri ) , {
complete : countComplete
} ) . statusCode ( createStatusCodes ( "immediately with method" , isSuccess ) ) ;
jQuery . ajax ( url ( uri ) , {
complete : function ( jqXHR ) {
jqXHR . statusCode ( createStatusCodes ( "on complete" , isSuccess ) ) ;
countComplete ( ) ;
}
} ) ;
jQuery . ajax ( url ( uri ) , {
complete : function ( jqXHR ) {
setTimeout ( function ( ) {
jqXHR . statusCode ( createStatusCodes ( "very late binding" , isSuccess ) ) ;
countComplete ( ) ;
} , 100 ) ;
}
} ) ;
jQuery . ajax ( url ( uri ) , {
statusCode : createStatusCodes ( "all (options)" , isSuccess ) ,
complete : function ( jqXHR ) {
jqXHR . statusCode ( createStatusCodes ( "all (on complete)" , isSuccess ) ) ;
setTimeout ( function ( ) {
jqXHR . statusCode ( createStatusCodes ( "all (very late binding)" , isSuccess ) ) ;
countComplete ( ) ;
} , 100 ) ;
}
} ) . statusCode ( createStatusCodes ( "all (immediately with method)" , isSuccess ) ) ;
var testString = "" ;
jQuery . ajax ( url ( uri ) , {
success : function ( a , b , jqXHR ) {
ok ( isSuccess , "success" ) ;
var statusCode = { } ;
statusCode [ jqXHR . status ] = function ( ) {
testString += "B" ;
} ;
jqXHR . statusCode ( statusCode ) ;
testString += "A" ;
} ,
error : function ( jqXHR ) {
ok ( ! isSuccess , "error" ) ;
var statusCode = { } ;
statusCode [ jqXHR . status ] = function ( ) {
testString += "B" ;
} ;
jqXHR . statusCode ( statusCode ) ;
testString += "A" ;
} ,
complete : function ( ) {
strictEqual (
testString ,
"AB" ,
"Test statusCode callbacks are ordered like " + ( isSuccess ? "success" : "error" ) + " callbacks"
) ;
countComplete ( ) ;
}
} ) ;
}
/* jQuery.each arguments end*/
) ;
2012-12-04 06:39:27 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - transitive conversions" , 8 , [
{
url : url ( "data/json.php" ) ,
converters : {
"json myJson" : function ( data ) {
ok ( true , "converter called" ) ;
return data ;
}
} ,
dataType : "myJson" ,
success : function ( ) {
ok ( true , "Transitive conversion worked" ) ;
strictEqual ( this . dataTypes [ 0 ] , "text" , "response was retrieved as text" ) ;
strictEqual ( this . dataTypes [ 1 ] , "myjson" , "request expected myjson dataType" ) ;
2012-11-26 02:31:19 +00:00
}
2012-12-05 13:54:14 +00:00
} ,
{
url : url ( "data/json.php" ) ,
converters : {
"json myJson" : function ( data ) {
ok ( true , "converter called (*)" ) ;
return data ;
2012-12-04 06:39:27 +00:00
}
2012-12-05 13:54:14 +00:00
} ,
contents : false , /* headers are wrong so we ignore them */
dataType : "* myJson" ,
success : function ( ) {
ok ( true , "Transitive conversion worked (*)" ) ;
strictEqual ( this . dataTypes [ 0 ] , "text" , "response was retrieved as text (*)" ) ;
strictEqual ( this . dataTypes [ 1 ] , "myjson" , "request expected myjson dataType (*)" ) ;
}
}
] ) ;
2012-11-26 02:31:19 +00:00
ajaxTest ( "jQuery.ajax() - overrideMimeType" , 2 , [
{
2012-12-05 13:54:14 +00:00
url : url ( "data/json.php" ) ,
2012-11-26 02:31:19 +00:00
beforeSend : function ( xhr ) {
xhr . overrideMimeType ( "application/json" ) ;
} ,
success : function ( json ) {
2013-02-27 20:44:34 +00:00
ok ( json . data , "Mimetype overridden using beforeSend" ) ;
2012-11-26 02:31:19 +00:00
}
} ,
{
2012-12-05 13:54:14 +00:00
url : url ( "data/json.php" ) ,
2012-11-26 02:31:19 +00:00
mimeType : "application/json" ,
success : function ( json ) {
2013-02-27 20:44:34 +00:00
ok ( json . data , "Mimetype overridden using mimeType option" ) ;
2012-11-26 02:31:19 +00:00
}
}
] ) ;
2012-12-05 13:54:14 +00:00
ajaxTest ( "jQuery.ajax() - empty json gets to error callback instead of success callback." , 1 , {
url : url ( "data/echoData.php" ) ,
error : function ( _ , _ _ , error ) {
equal ( typeof error === "object" , true , "Didn't get back error object for empty json response" ) ;
} ,
dataType : "json"
} ) ;
2012-11-26 02:31:19 +00:00
ajaxTest ( "#2688 - jQuery.ajax() - beforeSend, cancel request" , 2 , {
create : function ( ) {
return jQuery . ajax ( {
2012-12-05 13:54:14 +00:00
url : url ( "data/name.html" ) ,
2012-11-26 02:31:19 +00:00
beforeSend : function ( ) {
ok ( true , "beforeSend got called, canceling" ) ;
return false ;
} ,
success : function ( ) {
ok ( false , "request didn't get canceled" ) ;
} ,
complete : function ( ) {
ok ( false , "request didn't get canceled" ) ;
} ,
error : function ( ) {
ok ( false , "request didn't get canceled" ) ;
}
} ) ;
} ,
fail : function ( _ , reason ) {
strictEqual ( reason , "canceled" , "canceled request must fail with 'canceled' status text" ) ;
}
} ) ;
ajaxTest ( "#2806 - jQuery.ajax() - data option - evaluate function values" , 1 , {
2012-12-05 13:54:14 +00:00
url : "data/echoQuery.php" ,
2012-11-26 02:31:19 +00:00
data : {
2012-12-05 13:54:14 +00:00
key : function ( ) {
2012-11-26 02:31:19 +00:00
return "value" ;
}
} ,
success : function ( result ) {
2012-12-05 13:54:14 +00:00
strictEqual ( result , "key=value" ) ;
2012-11-26 02:31:19 +00:00
}
} ) ;
test ( "#7531 - jQuery.ajax() - Location object as url" , 1 , function ( ) {
2013-04-09 15:45:09 +00:00
var xhr ,
success = false ;
2012-11-26 02:31:19 +00:00
try {
2013-04-09 15:45:09 +00:00
xhr = jQuery . ajax ( {
2012-11-26 02:31:19 +00:00
url : window . location
} ) ;
success = true ;
xhr . abort ( ) ;
} catch ( e ) {
}
ok ( success , "document.location did not generate exception" ) ;
} ) ;
jQuery . each ( [ " - Same Domain" , " - Cross Domain" ] , function ( crossDomain , label ) {
ajaxTest ( "#7578 - jQuery.ajax() - JSONP - default for cache option" + label , 1 , {
2012-12-05 13:54:14 +00:00
url : "data/jsonp.php" ,
2012-11-26 02:31:19 +00:00
dataType : "jsonp" ,
crossDomain : crossDomain ,
2013-04-09 15:45:09 +00:00
beforeSend : function ( ) {
2012-12-05 13:54:14 +00:00
strictEqual ( this . cache , false , "cache must be false on JSON request" ) ;
2012-11-26 02:31:19 +00:00
return false ;
} ,
error : true
} ) ;
} ) ;
ajaxTest ( "#8107 - jQuery.ajax() - multiple method signatures introduced in 1.5" , 4 , [
{
create : function ( ) {
return jQuery . ajax ( ) ;
} ,
done : function ( ) {
ok ( true , "With no arguments" ) ;
}
} ,
{
create : function ( ) {
2012-12-05 13:54:14 +00:00
return jQuery . ajax ( "data/name.html" ) ;
2012-11-26 02:31:19 +00:00
} ,
done : function ( ) {
ok ( true , "With only string URL argument" ) ;
}
} ,
{
create : function ( ) {
2012-12-05 13:54:14 +00:00
return jQuery . ajax ( "data/name.html" , { } ) ;
2012-11-26 02:31:19 +00:00
} ,
done : function ( ) {
ok ( true , "With string URL param and map" ) ;
}
} ,
{
create : function ( options ) {
return jQuery . ajax ( options ) ;
} ,
2012-12-05 13:54:14 +00:00
url : "data/name.html" ,
2012-11-26 02:31:19 +00:00
success : function ( ) {
ok ( true , "With only map" ) ;
}
}
] ) ;
2013-03-13 23:23:36 +00:00
2012-11-26 02:31:19 +00:00
jQuery . each ( [ " - Same Domain" , " - Cross Domain" ] , function ( crossDomain , label ) {
ajaxTest ( "#8205 - jQuery.ajax() - JSONP - re-use callbacks name" + label , 2 , {
2012-12-05 13:54:14 +00:00
url : "data/jsonp.php" ,
2012-11-26 02:31:19 +00:00
dataType : "jsonp" ,
crossDomain : crossDomain ,
beforeSend : function ( jqXHR , s ) {
s . callback = s . jsonpCallback ;
} ,
success : function ( ) {
var previous = this ;
strictEqual ( previous . jsonpCallback , undefined , "jsonpCallback option is set back to default in callbacks" ) ;
jQuery . ajax ( {
2012-12-05 13:54:14 +00:00
url : "data/jsonp.php" ,
2012-11-26 02:31:19 +00:00
dataType : "jsonp" ,
crossDomain : crossDomain ,
beforeSend : function ( ) {
strictEqual ( this . jsonpCallback , previous . callback , "JSONP callback name is re-used" ) ;
return false ;
}
} ) ;
}
} ) ;
} ) ;
test ( "#9887 - jQuery.ajax() - Context with circular references (#9887)" , 2 , function ( ) {
var success = false ,
context = { } ;
context . field = context ;
try {
2012-12-05 13:54:14 +00:00
jQuery . ajax ( "non-existing" , {
2012-11-26 02:31:19 +00:00
context : context ,
beforeSend : function ( ) {
ok ( this === context , "context was not deep extended" ) ;
return false ;
}
} ) ;
success = true ;
} catch ( e ) {
console . log ( e ) ;
}
ok ( success , "context with circular reference did not generate an exception" ) ;
} ) ;
2012-12-05 13:54:14 +00:00
jQuery . each ( [ "as argument" , "in settings object" ] , function ( inSetting , title ) {
2013-03-13 23:23:36 +00:00
2012-11-26 02:31:19 +00:00
function request ( url , test ) {
return {
create : function ( ) {
return jQuery . ajax ( inSetting ? { url : url } : url ) ;
} ,
done : function ( ) {
ok ( true , ( test || url ) + " " + title ) ;
}
} ;
}
2013-03-13 23:23:36 +00:00
2012-12-05 13:54:14 +00:00
ajaxTest ( "#10093 - jQuery.ajax() - falsy url " + title , 4 , [
2012-11-26 02:31:19 +00:00
request ( "" , "empty string" ) ,
request ( false ) ,
request ( null ) ,
request ( undefined )
] ) ;
2013-03-13 23:23:36 +00:00
2012-11-26 02:31:19 +00:00
} ) ;
2013-02-08 15:26:36 +00:00
ajaxTest ( "#11151 - jQuery.ajax() - parse error body" , 2 , {
url : url ( "data/errorWithJSON.php" ) ,
dataFilter : function ( string ) {
ok ( false , "dataFilter called" ) ;
return string ;
} ,
error : function ( jqXHR ) {
strictEqual ( jqXHR . responseText , "{ \"code\": 40, \"message\": \"Bad Request\" }" , "Error body properly set" ) ;
deepEqual ( jqXHR . responseJSON , { code : 40 , message : "Bad Request" } , "Error body properly parsed" ) ;
}
} ) ;
2012-11-26 02:31:19 +00:00
ajaxTest ( "#11426 - jQuery.ajax() - loading binary data shouldn't throw an exception in IE" , 1 , {
url : url ( "data/1x1.jpg" ) ,
success : function ( data ) {
ok ( data === undefined || /JFIF/ . test ( data ) , "success callback reached" ) ;
}
} ) ;
2014-06-15 21:45:24 +00:00
asyncTest ( "#11743 - jQuery.ajax() - script, throws exception" , 1 , function ( ) {
var onerror = window . onerror ;
window . onerror = function ( ) {
ok ( true , "Exception thrown" ) ;
window . onerror = onerror ;
start ( ) ;
} ;
jQuery . ajax ( {
url : "data/badjson.js" ,
dataType : "script" ,
"throws" : true
} ) ;
2012-11-26 02:31:19 +00:00
} ) ;
2012-11-28 23:15:17 +00:00
jQuery . each ( [ "method" , "type" ] , function ( _ , globalOption ) {
function request ( option ) {
var options = {
2012-12-05 13:54:14 +00:00
url : url ( "data/echoData.php" ) ,
data : "hello" ,
2012-11-28 23:15:17 +00:00
success : function ( msg ) {
strictEqual ( msg , "hello" , "Check for POST (no override)" ) ;
}
} ;
if ( option ) {
options [ option ] = "GET" ;
options . success = function ( msg ) {
strictEqual ( msg , "" , "Check for no POST (overriding with " + option + ")" ) ;
} ;
}
return options ;
}
ajaxTest ( "#12004 - jQuery.ajax() - method is an alias of type - " + globalOption + " set globally" , 3 , {
setup : function ( ) {
var options = { } ;
options [ globalOption ] = "POST" ;
jQuery . ajaxSetup ( options ) ;
} ,
requests : [
request ( "type" ) ,
request ( "method" ) ,
request ( )
]
} ) ;
2013-03-13 23:23:36 +00:00
2012-11-28 23:15:17 +00:00
} ) ;
2013-01-21 01:44:16 +00:00
ajaxTest ( "#13276 - jQuery.ajax() - compatibility between XML documents from ajax requests and parsed string" , 1 , {
url : "data/dashboard.xml" ,
dataType : "xml" ,
success : function ( ajaxXML ) {
var parsedXML = jQuery ( jQuery . parseXML ( "<tab title=\"Added\">blibli</tab>" ) ) . find ( "tab" ) ;
ajaxXML = jQuery ( ajaxXML ) ;
try {
2014-05-05 13:45:57 +00:00
// Android 2.3 doesn't automatically adopt nodes from foreign documents.
// (see the comment in test/manipulation.js)
// Support: Android 2.3
if ( /android 2\.3/i . test ( navigator . userAgent ) ) {
parsedXML = jQuery ( ajaxXML [ 0 ] . adoptNode ( parsedXML [ 0 ] ) ) ;
}
2013-01-21 01:44:16 +00:00
ajaxXML . find ( "infowindowtab" ) . append ( parsedXML ) ;
} catch ( e ) {
strictEqual ( e , undefined , "error" ) ;
return ;
}
strictEqual ( ajaxXML . find ( "tab" ) . length , 3 , "Parsed node was added properly" ) ;
}
} ) ;
2013-03-13 23:23:36 +00:00
2013-01-24 01:33:17 +00:00
ajaxTest ( "#13292 - jQuery.ajax() - converter is bypassed for 204 requests" , 3 , {
url : "data/nocontent.php" ,
dataType : "testing" ,
converters : {
"* testing" : function ( ) {
throw "converter was called" ;
}
} ,
success : function ( data , status , jqXHR ) {
strictEqual ( jqXHR . status , 204 , "status code is 204" ) ;
strictEqual ( status , "nocontent" , "status text is 'nocontent'" ) ;
strictEqual ( data , undefined , "data is undefined" ) ;
} ,
error : function ( _ , status , error ) {
ok ( false , "error" ) ;
strictEqual ( status , "parsererror" , "Parser Error" ) ;
strictEqual ( error , "converter was called" , "Converter was called" ) ;
}
} ) ;
2013-01-21 01:44:16 +00:00
2013-02-08 15:26:36 +00:00
ajaxTest ( "#13388 - jQuery.ajax() - responseXML" , 3 , {
url : url ( "data/with_fries.xml" ) ,
dataType : "xml" ,
success : function ( resp , _ , jqXHR ) {
notStrictEqual ( resp , undefined , "XML document exists" ) ;
ok ( "responseXML" in jqXHR , "jqXHR.responseXML exists" ) ;
strictEqual ( resp , jqXHR . responseXML , "jqXHR.responseXML is set correctly" ) ;
}
} ) ;
2013-05-23 00:11:37 +00:00
ajaxTest ( "#13922 - jQuery.ajax() - converter is bypassed for HEAD requests" , 3 , {
url : "data/json.php" ,
method : "HEAD" ,
data : {
header : "yes"
} ,
converters : {
"text json" : function ( ) {
throw "converter was called" ;
}
} ,
success : function ( data , status ) {
ok ( true , "success" ) ;
strictEqual ( status , "nocontent" , "data is undefined" ) ;
strictEqual ( data , undefined , "data is undefined" ) ;
} ,
error : function ( _ , status , error ) {
ok ( false , "error" ) ;
strictEqual ( status , "parsererror" , "Parser Error" ) ;
strictEqual ( error , "converter was called" , "Converter was called" ) ;
}
} ) ;
2013-12-22 04:53:19 +00:00
ajaxTest ( "#13240 - jQuery.ajax() - support non-RFC2616 methods" , 1 , {
url : "data/echoQuery.php" ,
method : "PATCH" ,
success : function ( ) {
ok ( true , "success" ) ;
} ,
error : function ( ) {
ok ( false , "error" ) ;
}
} ) ;
2014-03-10 14:03:03 +00:00
testIframeWithCallback ( "#14379 - jQuery.ajax() on unload" , "ajax/onunload.html" , function ( status ) {
expect ( 1 ) ;
strictEqual ( status , "success" , "Request completed" ) ;
} ) ;
2013-10-28 21:40:13 +00:00
2012-11-26 02:31:19 +00:00
//----------- jQuery.ajaxPrefilter()
ajaxTest ( "jQuery.ajaxPrefilter() - abort" , 1 , {
2013-09-12 20:49:15 +00:00
dataType : "prefix" ,
2012-11-26 02:31:19 +00:00
setup : function ( ) {
2013-09-12 20:25:23 +00:00
// Ensure prefix does not throw an error
2013-09-12 20:49:15 +00:00
jQuery . ajaxPrefilter ( "+prefix" , function ( options , _ , jqXHR ) {
2012-11-26 02:31:19 +00:00
if ( options . abortInPrefilter ) {
jqXHR . abort ( ) ;
}
} ) ;
} ,
abortInPrefilter : true ,
error : function ( ) {
ok ( false , "error callback called" ) ;
} ,
fail : function ( _ , reason ) {
strictEqual ( reason , "canceled" , "Request aborted by the prefilter must fail with 'canceled' status text" ) ;
}
} ) ;
//----------- jQuery.ajaxSetup()
asyncTest ( "jQuery.ajaxSetup()" , 1 , function ( ) {
jQuery . ajaxSetup ( {
2012-12-05 13:54:14 +00:00
url : url ( "data/name.php?name=foo" ) ,
2012-11-26 02:31:19 +00:00
success : function ( msg ) {
strictEqual ( msg , "bar" , "Check for GET" ) ;
start ( ) ;
}
} ) ;
jQuery . ajax ( ) ;
} ) ;
2012-12-05 13:54:14 +00:00
asyncTest ( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout" , 2 , function ( ) {
var passed = 0 ,
pass = function ( ) {
ok ( passed ++ < 2 , "Error callback executed" ) ;
2013-04-09 15:45:09 +00:00
if ( passed === 2 ) {
2012-12-05 13:54:14 +00:00
jQuery ( document ) . off ( "ajaxError.setupTest" ) ;
start ( ) ;
}
} ,
2013-04-09 15:45:09 +00:00
fail = function ( a , b ) {
2012-12-05 13:54:14 +00:00
ok ( false , "Check for timeout failed " + a + " " + b ) ;
start ( ) ;
} ;
jQuery ( document ) . on ( "ajaxError.setupTest" , pass ) ;
jQuery . ajaxSetup ( {
timeout : 1000
} ) ;
jQuery . ajax ( {
type : "GET" ,
url : url ( "data/name.php?wait=5" ) ,
error : pass ,
success : fail
} ) ;
2012-11-26 02:31:19 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
asyncTest ( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout" , 1 , function ( ) {
jQuery . ajaxSetup ( {
timeout : 50
} ) ;
jQuery . ajax ( {
type : "GET" ,
timeout : 15000 ,
url : url ( "data/name.php?wait=1" ) ,
error : function ( ) {
ok ( false , "Check for local timeout failed" ) ;
start ( ) ;
} ,
success : function ( ) {
ok ( true , "Check for local timeout" ) ;
start ( ) ;
}
} ) ;
2012-11-26 02:31:19 +00:00
} ) ;
//----------- jQuery.domManip()
test ( "#11264 - jQuery.domManip() - no side effect because of ajaxSetup or global events" , 1 , function ( ) {
jQuery . ajaxSetup ( {
type : "POST"
} ) ;
2013-03-04 02:22:11 +00:00
jQuery ( document ) . on ( "ajaxStart ajaxStop" , function ( ) {
2012-11-26 02:31:19 +00:00
ok ( false , "Global event triggered" ) ;
} ) ;
2012-12-05 13:54:14 +00:00
jQuery ( "#qunit-fixture" ) . append ( "<script src='data/evalScript.php'></script>" ) ;
2013-03-04 02:22:11 +00:00
jQuery ( document ) . off ( "ajaxStart ajaxStop" ) ;
2012-11-26 02:31:19 +00:00
} ) ;
2011-01-21 02:58:28 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "#11402 - jQuery.domManip() - script in comments are properly evaluated" , 2 , function ( ) {
2012-12-05 13:54:14 +00:00
jQuery ( "#qunit-fixture" ) . load ( "data/cleanScript.html" , start ) ;
2012-11-26 02:31:19 +00:00
} ) ;
2011-01-21 02:58:28 +00:00
2012-11-26 02:31:19 +00:00
//----------- jQuery.get()
2011-01-21 02:58:28 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes" , 2 , function ( ) {
2012-12-05 13:54:14 +00:00
jQuery . get ( url ( "data/dashboard.xml" ) , function ( xml ) {
var content = [ ] ;
jQuery ( "tab" , xml ) . each ( function ( ) {
content . push ( jQuery ( this ) . text ( ) ) ;
2012-11-26 02:31:19 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
strictEqual ( content [ 0 ] , "blabla" , "Check first tab" ) ;
strictEqual ( content [ 1 ] , "blublu" , "Check second tab" ) ;
2012-10-15 19:53:39 +00:00
start ( ) ;
} ) ;
2012-11-26 02:31:19 +00:00
} ) ;
2011-01-21 02:58:28 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings" , 1 , function ( ) {
jQuery . ajaxSetup ( {
2012-12-05 13:54:14 +00:00
data : "helloworld"
2012-11-26 02:31:19 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
jQuery . get ( url ( "data/echoQuery.php" ) , function ( data ) {
ok ( /helloworld$/ . test ( data ) , "Data from ajaxSettings was used" ) ;
2012-11-26 02:31:19 +00:00
start ( ) ;
} ) ;
2011-10-01 20:49:49 +00:00
} ) ;
2011-01-21 02:58:28 +00:00
2012-11-26 02:31:19 +00:00
//----------- jQuery.getJSON()
2011-02-09 16:47:33 +00:00
2012-12-05 13:54:14 +00:00
asyncTest ( "jQuery.getJSON( String, Hash, Function ) - JSON array" , 5 , function ( ) {
2012-11-26 02:31:19 +00:00
jQuery . getJSON (
2012-12-05 13:54:14 +00:00
url ( "data/json.php" ) ,
2012-11-26 02:31:19 +00:00
{
2012-12-05 13:54:14 +00:00
"json" : "array"
2012-11-26 02:31:19 +00:00
} ,
function ( json ) {
2012-12-05 13:54:14 +00:00
ok ( json . length >= 2 , "Check length" ) ;
strictEqual ( json [ 0 ] [ "name" ] , "John" , "Check JSON: first, name" ) ;
strictEqual ( json [ 0 ] [ "age" ] , 21 , "Check JSON: first, age" ) ;
strictEqual ( json [ 1 ] [ "name" ] , "Peter" , "Check JSON: second, name" ) ;
strictEqual ( json [ 1 ] [ "age" ] , 25 , "Check JSON: second, age" ) ;
2012-11-26 02:31:19 +00:00
start ( ) ;
}
) ;
} ) ;
2011-02-09 16:47:33 +00:00
2012-12-05 13:54:14 +00:00
asyncTest ( "jQuery.getJSON( String, Function ) - JSON object" , 2 , function ( ) {
jQuery . getJSON ( url ( "data/json.php" ) , function ( json ) {
if ( json && json [ "data" ] ) {
strictEqual ( json [ "data" ] [ "lang" ] , "en" , "Check JSON: lang" ) ;
strictEqual ( json [ "data" ] . length , 25 , "Check JSON: length" ) ;
start ( ) ;
}
2012-11-26 02:31:19 +00:00
} ) ;
} ) ;
2011-02-09 16:47:33 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "jQuery.getJSON() - Using Native JSON" , 2 , function ( ) {
var restore = "JSON" in window ,
old = window . JSON ;
if ( ! restore ) {
Globals . register ( "JSON" ) ;
}
window . JSON = {
2013-04-09 15:45:09 +00:00
parse : function ( ) {
2012-11-26 02:31:19 +00:00
ok ( true , "Verifying that parse method was run" ) ;
window . JSON = old ;
return true ;
}
} ;
2012-12-05 13:54:14 +00:00
jQuery . getJSON ( url ( "data/json.php" ) , function ( json ) {
2012-11-26 02:31:19 +00:00
strictEqual ( json , true , "Verifying return value" ) ;
2012-10-15 19:53:39 +00:00
start ( ) ;
} ) ;
2012-11-26 02:31:19 +00:00
} ) ;
2011-02-09 16:47:33 +00:00
2012-12-05 13:54:14 +00:00
asyncTest ( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content" , 2 , function ( ) {
jQuery . getJSON ( url ( window . location . href . replace ( /[^\/]*$/ , "" ) + "data/json.php" ) , function ( json ) {
strictEqual ( json . data . lang , "en" , "Check JSON: lang" ) ;
strictEqual ( json . data . length , 25 , "Check JSON: length" ) ;
2012-11-26 02:31:19 +00:00
start ( ) ;
} ) ;
2011-10-01 20:49:49 +00:00
} ) ;
2011-02-09 16:47:33 +00:00
2012-11-26 02:31:19 +00:00
//----------- jQuery.getScript()
2011-02-09 16:47:33 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "jQuery.getScript( String, Function ) - with callback" , 2 , function ( ) {
2012-12-03 04:32:16 +00:00
Globals . register ( "testBar" ) ;
2014-04-04 18:31:38 +00:00
jQuery . getScript ( url ( "data/testbar.php" ) , function ( ) {
2012-12-05 13:54:14 +00:00
strictEqual ( window [ "testBar" ] , "bar" , "Check if script was evaluated" ) ;
2012-11-26 02:31:19 +00:00
start ( ) ;
} ) ;
} ) ;
2011-02-04 21:19:23 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "jQuery.getScript( String, Function ) - no callback" , 1 , function ( ) {
2012-12-03 04:32:16 +00:00
Globals . register ( "testBar" ) ;
2014-04-04 18:31:38 +00:00
jQuery . getScript ( url ( "data/testbar.php" ) ) . done ( start ) ;
2012-11-26 02:31:19 +00:00
} ) ;
asyncTest ( "#8082 - jQuery.getScript( String, Function ) - source as responseText" , 2 , function ( ) {
2012-12-03 04:32:16 +00:00
Globals . register ( "testBar" ) ;
2014-04-04 18:31:38 +00:00
jQuery . getScript ( url ( "data/testbar.php" ) , function ( data , _ , jqXHR ) {
2012-11-26 02:31:19 +00:00
strictEqual ( data , jqXHR . responseText , "Same-domain script requests returns the source of the script" ) ;
start ( ) ;
2012-10-15 19:53:39 +00:00
} ) ;
2012-11-26 02:31:19 +00:00
} ) ;
2011-02-04 21:19:23 +00:00
2012-11-26 02:31:19 +00:00
//----------- jQuery.fn.load()
2013-03-13 23:23:36 +00:00
2012-11-26 02:31:19 +00:00
// check if load can be called with only url
asyncTest ( "jQuery.fn.load( String )" , 2 , function ( ) {
jQuery . ajaxSetup ( {
beforeSend : function ( ) {
strictEqual ( this . type , "GET" , "no data means GET request" ) ;
2012-10-15 19:53:39 +00:00
}
} ) ;
2012-12-05 13:54:14 +00:00
jQuery ( "#first" ) . load ( "data/name.html" , start ) ;
2012-11-26 02:31:19 +00:00
} ) ;
2011-02-04 21:19:23 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "jQuery.fn.load() - 404 error callbacks" , 6 , function ( ) {
2012-12-02 15:48:26 +00:00
addGlobalEvents ( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError" ) ( ) ;
2012-12-05 13:54:14 +00:00
jQuery ( document ) . ajaxStop ( start ) ;
jQuery ( "<div/>" ) . load ( "data/404.html" , function ( ) {
2012-11-26 02:31:19 +00:00
ok ( true , "complete" ) ;
} ) ;
2012-04-01 23:54:19 +00:00
} ) ;
2011-02-04 21:19:23 +00:00
2012-11-26 02:31:19 +00:00
// check if load can be called with url and null data
asyncTest ( "jQuery.fn.load( String, null )" , 2 , function ( ) {
jQuery . ajaxSetup ( {
beforeSend : function ( ) {
2012-12-05 13:54:14 +00:00
strictEqual ( this . type , "GET" , "no data means GET request" ) ;
2012-10-15 19:53:39 +00:00
}
} ) ;
2012-12-05 13:54:14 +00:00
jQuery ( "#first" ) . load ( "data/name.html" , null , start ) ;
2012-03-07 14:39:39 +00:00
} ) ;
2012-11-26 02:31:19 +00:00
// check if load can be called with url and undefined data
asyncTest ( "jQuery.fn.load( String, undefined )" , 2 , function ( ) {
2012-10-15 19:53:39 +00:00
jQuery . ajaxSetup ( {
2012-11-26 02:31:19 +00:00
beforeSend : function ( ) {
2012-12-05 13:54:14 +00:00
strictEqual ( this . type , "GET" , "no data means GET request" ) ;
2012-11-26 02:31:19 +00:00
}
2012-10-15 19:53:39 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
jQuery ( "#first" ) . load ( "data/name.html" , undefined , start ) ;
2012-11-26 02:31:19 +00:00
} ) ;
2012-03-07 15:54:05 +00:00
2012-11-26 02:31:19 +00:00
// check if load can be called with only url
asyncTest ( "jQuery.fn.load( URL_SELECTOR )" , 1 , function ( ) {
2012-12-05 13:54:14 +00:00
jQuery ( "#first" ) . load ( "data/test3.html div.user" , function ( ) {
2012-11-26 02:31:19 +00:00
strictEqual ( jQuery ( this ) . children ( "div" ) . length , 2 , "Verify that specific elements were injected" ) ;
start ( ) ;
2012-10-15 19:53:39 +00:00
} ) ;
2012-11-26 02:31:19 +00:00
} ) ;
2012-03-07 15:54:05 +00:00
2014-03-04 02:37:56 +00:00
// Selector should be trimmed to avoid leading spaces (#14773)
asyncTest ( "jQuery.fn.load( URL_SELECTOR with spaces )" , 1 , function ( ) {
jQuery ( "#first" ) . load ( "data/test3.html #superuser " , function ( ) {
strictEqual ( jQuery ( this ) . children ( "div" ) . length , 1 , "Verify that specific elements were injected" ) ;
start ( ) ;
} ) ;
} ) ;
2012-11-26 02:31:19 +00:00
asyncTest ( "jQuery.fn.load( String, Function ) - simple: inject text into DOM" , 2 , function ( ) {
2012-12-05 13:54:14 +00:00
jQuery ( "#first" ) . load ( url ( "data/name.html" ) , function ( ) {
ok ( /^ERROR/ . test ( jQuery ( "#first" ) . text ( ) ) , "Check if content was injected into the DOM" ) ;
2012-11-26 02:31:19 +00:00
start ( ) ;
} ) ;
} ) ;
2012-03-07 15:54:05 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "jQuery.fn.load( String, Function ) - check scripts" , 7 , function ( ) {
var verifyEvaluation = function ( ) {
2012-12-03 04:32:16 +00:00
strictEqual ( window [ "testBar" ] , "bar" , "Check if script src was evaluated after load" ) ;
2012-11-26 02:31:19 +00:00
strictEqual ( jQuery ( "#ap" ) . html ( ) , "bar" , "Check if script evaluation has modified DOM" ) ;
start ( ) ;
} ;
2012-12-03 04:32:16 +00:00
Globals . register ( "testFoo" ) ;
Globals . register ( "testBar" ) ;
2012-12-05 13:54:14 +00:00
jQuery ( "#first" ) . load ( url ( "data/test.html" ) , function ( ) {
2012-11-26 02:31:19 +00:00
ok ( jQuery ( "#first" ) . html ( ) . match ( /^html text/ ) , "Check content after loading html" ) ;
strictEqual ( jQuery ( "#foo" ) . html ( ) , "foo" , "Check if script evaluation has modified DOM" ) ;
strictEqual ( window [ "testFoo" ] , "foo" , "Check if script was evaluated after load" ) ;
setTimeout ( verifyEvaluation , 600 ) ;
} ) ;
} ) ;
asyncTest ( "jQuery.fn.load( String, Function ) - check file with only a script tag" , 3 , function ( ) {
2012-12-05 13:54:14 +00:00
Globals . register ( "testFoo" ) ;
jQuery ( "#first" ) . load ( url ( "data/test2.html" ) , function ( ) {
2012-11-26 02:31:19 +00:00
strictEqual ( jQuery ( "#foo" ) . html ( ) , "foo" , "Check if script evaluation has modified DOM" ) ;
strictEqual ( window [ "testFoo" ] , "foo" , "Check if script was evaluated after load" ) ;
start ( ) ;
} ) ;
} ) ;
2012-03-07 15:54:05 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings" , 2 , function ( ) {
2012-10-15 19:53:39 +00:00
jQuery . ajaxSetup ( {
2012-11-26 02:31:19 +00:00
dataFilter : function ( ) {
return "Hello World" ;
}
} ) ;
2012-12-05 13:54:14 +00:00
jQuery ( "<div/>" ) . load ( url ( "data/name.html" ) , function ( responseText ) {
2012-11-26 02:31:19 +00:00
strictEqual ( jQuery ( this ) . html ( ) , "Hello World" , "Test div was filled with filtered data" ) ;
strictEqual ( responseText , "Hello World" , "Test callback receives filtered data" ) ;
start ( ) ;
2012-10-15 19:53:39 +00:00
} ) ;
2012-03-07 15:54:05 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
asyncTest ( "jQuery.fn.load( String, Object, Function )" , 2 , function ( ) {
jQuery ( "<div />" ) . load ( url ( "data/params_html.php" ) , {
"foo" : 3 ,
"bar" : "ok"
2012-11-26 02:31:19 +00:00
} , function ( ) {
2012-12-05 13:54:14 +00:00
var $post = jQuery ( this ) . find ( "#post" ) ;
strictEqual ( $post . find ( "#foo" ) . text ( ) , "3" , "Check if a hash of data is passed correctly" ) ;
strictEqual ( $post . find ( "#bar" ) . text ( ) , "ok" , "Check if a hash of data is passed correctly" ) ;
2012-10-15 19:53:39 +00:00
start ( ) ;
} ) ;
2012-05-05 23:27:01 +00:00
} ) ;
2011-01-19 17:44:21 +00:00
2012-12-05 13:54:14 +00:00
asyncTest ( "jQuery.fn.load( String, String, Function )" , 2 , function ( ) {
jQuery ( "<div />" ) . load ( url ( "data/params_html.php" ) , "foo=3&bar=ok" , function ( ) {
var $get = jQuery ( this ) . find ( "#get" ) ;
strictEqual ( $get . find ( "#foo" ) . text ( ) , "3" , "Check if a string of data is passed correctly" ) ;
strictEqual ( $get . find ( "#bar" ) . text ( ) , "ok" , "Check if a of data is passed correctly" ) ;
2012-11-26 02:31:19 +00:00
start ( ) ;
} ) ;
2012-10-15 19:53:39 +00:00
} ) ;
2012-10-16 15:37:15 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "jQuery.fn.load() - callbacks get the correct parameters" , 8 , function ( ) {
2013-04-09 15:45:09 +00:00
var completeArgs = { } ;
2012-10-16 15:37:15 +00:00
2012-11-26 02:31:19 +00:00
jQuery . ajaxSetup ( {
success : function ( _ , status , jqXHR ) {
completeArgs [ this . url ] = [ jqXHR . responseText , status , jqXHR ] ;
} ,
error : function ( jqXHR , status ) {
completeArgs [ this . url ] = [ jqXHR . responseText , status , jqXHR ] ;
}
} ) ;
2012-10-16 15:37:15 +00:00
2012-11-26 02:31:19 +00:00
jQuery . when . apply (
jQuery ,
jQuery . map ( [
{
type : "success" ,
2012-12-05 13:54:14 +00:00
url : "data/echoQuery.php?arg=pop"
2012-11-26 02:31:19 +00:00
} ,
{
type : "error" ,
2012-12-05 13:54:14 +00:00
url : "data/404.php"
2012-11-26 02:31:19 +00:00
}
] ,
function ( options ) {
return jQuery . Deferred ( function ( defer ) {
jQuery ( "#foo" ) . load ( options . url , function ( ) {
var args = arguments ;
strictEqual ( completeArgs [ options . url ] . length , args . length , "same number of arguments (" + options . type + ")" ) ;
jQuery . each ( completeArgs [ options . url ] , function ( i , value ) {
strictEqual ( args [ i ] , value , "argument #" + i + " is the same (" + options . type + ")" ) ;
} ) ;
defer . resolve ( ) ;
} ) ;
} ) ;
} )
) . always ( start ) ;
} ) ;
2012-10-16 15:37:15 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json" , 1 , function ( ) {
jQuery . ajaxSetup ( {
dataType : "json"
} ) ;
2012-12-01 20:25:52 +00:00
jQuery ( document ) . ajaxComplete ( function ( e , xml , s ) {
2012-11-26 02:31:19 +00:00
strictEqual ( s . dataType , "html" , "Verify the load() dataType was html" ) ;
2013-03-04 02:22:11 +00:00
jQuery ( document ) . off ( "ajaxComplete" ) ;
2012-10-16 15:37:15 +00:00
start ( ) ;
} ) ;
2012-12-05 13:54:14 +00:00
jQuery ( "#first" ) . load ( "data/test3.html" ) ;
2012-10-16 15:37:15 +00:00
} ) ;
2012-12-05 13:54:14 +00:00
asyncTest ( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in" , 1 , function ( ) {
var data = {
"baz" : 1
} ;
2012-11-26 02:31:19 +00:00
jQuery . ajaxSetup ( {
data : {
"foo" : "bar"
}
} ) ;
2012-12-05 13:54:14 +00:00
jQuery ( "#foo" ) . load ( "data/echoQuery.php" , data ) ;
jQuery ( document ) . ajaxComplete ( function ( event , jqXHR , options ) {
ok ( ~ options . data . indexOf ( "foo=bar" ) , "Data from ajaxSettings was used" ) ;
start ( ) ;
2012-12-01 20:25:52 +00:00
} ) ;
2012-11-26 02:31:19 +00:00
} ) ;
2012-10-16 15:37:15 +00:00
2012-11-26 02:31:19 +00:00
//----------- jQuery.post()
2012-10-16 15:37:15 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "jQuery.post() - data" , 3 , function ( ) {
2012-10-16 15:37:15 +00:00
jQuery . when (
2012-11-26 02:31:19 +00:00
jQuery . post (
2012-12-05 13:54:14 +00:00
url ( "data/name.php" ) ,
2012-11-26 02:31:19 +00:00
{
2012-12-05 13:54:14 +00:00
xml : "5-2" ,
length : 3
2012-11-26 02:31:19 +00:00
} ,
function ( xml ) {
jQuery ( "math" , xml ) . each ( function ( ) {
2012-11-27 01:38:20 +00:00
strictEqual ( jQuery ( "calculation" , this ) . text ( ) , "5-2" , "Check for XML" ) ;
strictEqual ( jQuery ( "result" , this ) . text ( ) , "3" , "Check for XML" ) ;
2012-11-26 02:31:19 +00:00
} ) ;
}
) ,
jQuery . ajax ( {
2012-12-05 13:54:14 +00:00
url : url ( "data/echoData.php" ) ,
2012-11-26 02:31:19 +00:00
type : "POST" ,
data : {
2012-12-05 13:54:14 +00:00
"test" : {
"length" : 7 ,
"foo" : "bar"
2012-11-26 02:31:19 +00:00
}
} ,
success : function ( data ) {
strictEqual ( data , "test%5Blength%5D=7&test%5Bfoo%5D=bar" , "Check if a sub-object with a length param is serialized correctly" ) ;
}
} )
2014-04-04 18:31:38 +00:00
) . always ( function ( ) {
start ( ) ;
} ) ;
2012-10-16 15:37:15 +00:00
} ) ;
2012-11-03 04:06:50 +00:00
2012-11-26 02:31:19 +00:00
asyncTest ( "jQuery.post( String, Hash, Function ) - simple with xml" , 4 , function ( ) {
jQuery . when (
jQuery . post (
2012-12-05 13:54:14 +00:00
url ( "data/name.php" ) ,
2012-11-26 02:31:19 +00:00
{
2012-12-05 13:54:14 +00:00
"xml" : "5-2"
2012-11-26 02:31:19 +00:00
} ,
function ( xml ) {
jQuery ( "math" , xml ) . each ( function ( ) {
strictEqual ( jQuery ( "calculation" , this ) . text ( ) , "5-2" , "Check for XML" ) ;
strictEqual ( jQuery ( "result" , this ) . text ( ) , "3" , "Check for XML" ) ;
} ) ;
}
) ,
2012-12-05 13:54:14 +00:00
jQuery . post ( url ( "data/name.php?xml=5-2" ) , { } , function ( xml ) {
2012-11-26 02:31:19 +00:00
jQuery ( "math" , xml ) . each ( function ( ) {
strictEqual ( jQuery ( "calculation" , this ) . text ( ) , "5-2" , "Check for XML" ) ;
strictEqual ( jQuery ( "result" , this ) . text ( ) , "3" , "Check for XML" ) ;
} ) ;
} )
2014-04-04 18:31:38 +00:00
) . always ( function ( ) {
start ( ) ;
} ) ;
2012-11-26 02:31:19 +00:00
} ) ;
2012-10-16 18:51:54 +00:00
2012-11-26 02:31:19 +00:00
//----------- jQuery.active
2012-10-16 18:51:54 +00:00
2012-11-26 02:31:19 +00:00
test ( "jQuery.active" , 1 , function ( ) {
ok ( jQuery . active === 0 , "ajax active counter should be zero: " + jQuery . active ) ;
2012-10-16 18:51:54 +00:00
} ) ;
2012-11-03 04:06:50 +00:00
} ) ( ) ;