Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
010a112e
Commit
010a112e
authored
Dec 11, 2006
by
Jörn Zaefferer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #471
parent
12d13d9a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
22 deletions
+58
-22
ajax.js
src/ajax/ajax.js
+36
-8
ajaxTest.js
src/ajax/ajaxTest.js
+22
-14
No files found.
src/ajax/ajax.js
View file @
010a112e
...
...
@@ -170,7 +170,10 @@ if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" )
/**
* Attach a function to be executed whenever an AJAX request completes.
*
* @example $("#msg").ajaxComplete(function(){
* The XMLHttpRequest and settings used for that request are passed
* as arguments to the callback.
*
* @example $("#msg").ajaxComplete(function(request, settings){
* $(this).append("<li>Request Complete.</li>");
* });
* @desc Show a message when an AJAX request completes.
...
...
@@ -185,7 +188,10 @@ if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" )
* Attach a function to be executed whenever an AJAX request completes
* successfully.
*
* @example $("#msg").ajaxSuccess(function(){
* The XMLHttpRequest and settings used for that request are passed
* as arguments to the callback.
*
* @example $("#msg").ajaxSuccess(function(request, settings){
* $(this).append("<li>Successful Request!</li>");
* });
* @desc Show a message when an AJAX request completes successfully.
...
...
@@ -199,8 +205,11 @@ if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" )
/**
* Attach a function to be executed whenever an AJAX request fails.
*
* @example $("#msg").ajaxError(function(){
* $(this).append("<li>Error requesting page.</li>");
* The XMLHttpRequest and settings used for that request are passed
* as arguments to the callback.
*
* @example $("#msg").ajaxError(function(request, settings){
* $(this).append("<li>Error requesting page " + settings.url + "</li>");
* });
* @desc Show a message when an AJAX request fails.
*
...
...
@@ -209,9 +218,26 @@ if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" )
* @param Function callback The function to execute.
* @cat AJAX
*/
/**
* Attach a function to be executed before an AJAX request is send.
*
* The XMLHttpRequest and settings used for that request are passed
* as arguments to the callback.
*
* @example $("#msg").ajaxSend(function(request, settings){
* $(this).append("<li>Starting request at " + settings.url + "</li>");
* });
* @desc Show a message before an AJAX request is send.
*
* @name ajaxSend
* @type jQuery
* @param Function callback The function to execute.
* @cat AJAX
*/
new
function
(){
var
e
=
"ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess"
.
split
(
","
);
var
e
=
"ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess
,ajaxSend
"
.
split
(
","
);
for
(
var
i
=
0
;
i
<
e
.
length
;
i
++
)
new
function
(){
var
o
=
e
[
i
];
...
...
@@ -570,6 +596,8 @@ jQuery.extend({
// Allow custom headers/mimetypes
if
(
s
.
beforeSend
)
s
.
beforeSend
(
xml
);
if
(
s
.
global
)
jQuery
.
event
.
trigger
(
"ajaxSend"
,
[
xml
,
s
]);
// Wait for a response to come back
var
onreadystatechange
=
function
(
isTimeout
){
...
...
@@ -600,7 +628,7 @@ jQuery.extend({
// Fire the global callback
if
(
s
.
global
)
jQuery
.
event
.
trigger
(
"ajaxSuccess"
);
jQuery
.
event
.
trigger
(
"ajaxSuccess"
,
[
xml
,
s
]
);
// Otherwise, the request was not successful
}
else
{
...
...
@@ -609,12 +637,12 @@ jQuery.extend({
// Fire the global callback
if
(
s
.
global
)
jQuery
.
event
.
trigger
(
"ajaxError"
);
jQuery
.
event
.
trigger
(
"ajaxError"
,
[
xml
,
s
]
);
}
// The request was completed
if
(
s
.
global
)
jQuery
.
event
.
trigger
(
"ajaxComplete"
);
jQuery
.
event
.
trigger
(
"ajaxComplete"
,
[
xml
,
s
]
);
// Handle the global AJAX counter
if
(
s
.
global
&&
!
--
jQuery
.
active
)
...
...
src/ajax/ajaxTest.js
View file @
010a112e
...
...
@@ -55,47 +55,55 @@ test("load(String, Object, Function) - check scripts", function() {
});
test
(
"test global handlers - success"
,
function
()
{
expect
(
6
);
expect
(
8
);
stop
();
var
counter
=
{
complete
:
0
,
success
:
0
,
error
:
0
},
var
counter
=
{
complete
:
0
,
success
:
0
,
error
:
0
,
send
:
0
},
success
=
function
()
{
counter
.
success
++
},
error
=
function
()
{
counter
.
error
++
},
complete
=
function
()
{
counter
.
complete
++
};
complete
=
function
()
{
counter
.
complete
++
},
send
=
function
()
{
counter
.
send
++
};
$
(
'#foo'
).
ajaxStart
(
complete
).
ajaxStop
(
complete
).
ajaxComplete
(
complete
).
ajaxError
(
error
).
ajaxSuccess
(
success
);
$
(
'#foo'
).
ajaxStart
(
complete
).
ajaxStop
(
complete
).
ajax
Send
(
send
).
ajax
Complete
(
complete
).
ajaxError
(
error
).
ajaxSuccess
(
success
);
// start with successful test
$
.
ajax
({
url
:
"data/name.php"
,
success
:
success
,
error
:
error
,
complete
:
function
()
{
$
.
ajax
({
url
:
"data/name.php"
,
beforeSend
:
send
,
success
:
success
,
error
:
error
,
complete
:
function
()
{
ok
(
counter
.
error
==
0
,
'Check succesful request'
);
ok
(
counter
.
success
==
2
,
'Check succesful request'
);
ok
(
counter
.
complete
==
3
,
'Check succesful request'
);
counter
.
error
=
counter
.
success
=
counter
.
complete
=
0
;
ok
(
counter
.
send
==
2
,
'Check succesful request'
);
counter
.
error
=
counter
.
success
=
counter
.
complete
=
counter
.
send
=
0
;
$
.
ajaxTimeout
(
500
);
$
.
ajax
({
url
:
"data/name.php?wait=5"
,
success
:
success
,
error
:
error
,
complete
:
function
()
{
$
.
ajax
({
url
:
"data/name.php?wait=5"
,
beforeSend
:
send
,
success
:
success
,
error
:
error
,
complete
:
function
()
{
ok
(
counter
.
error
==
2
,
'Check failed request'
);
ok
(
counter
.
success
==
0
,
'Check failed request'
);
ok
(
counter
.
complete
==
3
,
'Check failed request'
);
ok
(
counter
.
send
==
2
,
'Check failed request'
);
start
();
}});
}});
});
test
(
"test global handlers - failure"
,
function
()
{
expect
(
6
);
expect
(
8
);
stop
();
var
counter
=
{
complete
:
0
,
success
:
0
,
error
:
0
},
var
counter
=
{
complete
:
0
,
success
:
0
,
error
:
0
,
send
:
0
},
success
=
function
()
{
counter
.
success
++
},
error
=
function
()
{
counter
.
error
++
};
error
=
function
()
{
counter
.
error
++
},
complete
=
function
()
{
counter
.
complete
++
},
send
=
function
()
{
counter
.
send
++
};
$
.
ajaxTimeout
(
0
);
$
.
ajax
({
url
:
"data/name.php"
,
global
:
false
,
success
:
success
,
error
:
error
,
complete
:
function
()
{
$
(
'#foo'
).
ajaxStart
(
complete
).
ajaxStop
(
complete
).
ajaxSend
(
send
).
ajaxComplete
(
complete
).
ajaxError
(
error
).
ajaxSuccess
(
success
);
$
.
ajax
({
url
:
"data/name.php"
,
global
:
false
,
beforeSend
:
send
,
success
:
success
,
error
:
error
,
complete
:
function
()
{
ok
(
counter
.
error
==
0
,
'Check sucesful request without globals'
);
ok
(
counter
.
success
==
1
,
'Check sucesful request without globals'
);
ok
(
counter
.
complete
==
0
,
'Check sucesful request without globals'
);
counter
.
error
=
counter
.
success
=
counter
.
complete
=
0
;
ok
(
counter
.
send
==
1
,
'Check sucesful request without globals'
);
counter
.
error
=
counter
.
success
=
counter
.
complete
=
counter
.
send
=
0
;
$
.
ajaxTimeout
(
500
);
$
.
ajax
({
url
:
"data/name.php?wait=5"
,
global
:
false
,
success
:
success
,
error
:
error
,
complete
:
function
()
{
$
.
ajax
({
url
:
"data/name.php?wait=5"
,
global
:
false
,
beforeSend
:
send
,
success
:
success
,
error
:
error
,
complete
:
function
()
{
ok
(
counter
.
error
==
1
,
'Check failed request without globals'
);
ok
(
counter
.
success
==
0
,
'Check failed request without globals'
);
ok
(
counter
.
complete
==
0
,
'Check failed request without globals'
);
ok
(
counter
.
send
==
1
,
'Check failed request without globals'
);
start
();
}});
}});
...
...
@@ -279,7 +287,7 @@ test("$.ajax - xml: non-namespace elements inside namespaced elements", function
});
});
test
(
"$.ajax -
preprocess
"
,
function
()
{
test
(
"$.ajax -
beforeSend
"
,
function
()
{
expect
(
1
);
stop
();
var
customHeader
=
"value"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment