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
62acda81
Commit
62acda81
authored
Jan 06, 2013
by
jaubourg
Committed by
Dave Methvin
Jan 07, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds the abort on unload trick back in since IE9 still exhibits the bug
parent
f6df0301
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
4 deletions
+49
-4
xhr.js
src/ajax/xhr.js
+19
-4
unreleasedXHR.html
test/data/ajax/unreleasedXHR.html
+25
-0
ajax.js
test/unit/ajax.js
+5
-0
No files found.
src/ajax/xhr.js
View file @
62acda81
...
@@ -11,8 +11,22 @@ var xhrSupported = jQuery.ajaxSettings.xhr(),
...
@@ -11,8 +11,22 @@ var xhrSupported = jQuery.ajaxSettings.xhr(),
// Support: IE9
// Support: IE9
// #1450: sometimes IE returns 1223 when it should be 204
// #1450: sometimes IE returns 1223 when it should be 204
1223
:
204
1223
:
204
};
},
// Support: IE9
// We need to keep track of outbound xhr and abort them manually
// because IE is not smart enough to do it all by itself
xhrId
=
0
,
xhrCallbacks
=
{};
if
(
window
.
ActiveXObject
)
{
jQuery
(
window
).
on
(
"unload"
,
function
()
{
for
(
var
key
in
xhrCallbacks
)
{
xhrCallbacks
[
key
]();
}
xhrCallbacks
=
undefined
;
});
}
jQuery
.
support
.
cors
=
!!
xhrSupported
&&
(
"withCredentials"
in
xhrSupported
);
jQuery
.
support
.
cors
=
!!
xhrSupported
&&
(
"withCredentials"
in
xhrSupported
);
jQuery
.
support
.
ajax
=
xhrSupported
=
!!
xhrSupported
;
jQuery
.
support
.
ajax
=
xhrSupported
=
!!
xhrSupported
;
...
@@ -22,7 +36,7 @@ jQuery.ajaxTransport(function( options ) {
...
@@ -22,7 +36,7 @@ jQuery.ajaxTransport(function( options ) {
if
(
jQuery
.
support
.
cors
||
xhrSupported
&&
!
options
.
crossDomain
)
{
if
(
jQuery
.
support
.
cors
||
xhrSupported
&&
!
options
.
crossDomain
)
{
return
{
return
{
send
:
function
(
headers
,
complete
)
{
send
:
function
(
headers
,
complete
)
{
var
i
,
var
i
,
id
,
xhr
=
options
.
xhr
();
xhr
=
options
.
xhr
();
xhr
.
open
(
options
.
type
,
options
.
url
,
options
.
async
,
options
.
username
,
options
.
password
);
xhr
.
open
(
options
.
type
,
options
.
url
,
options
.
async
,
options
.
username
,
options
.
password
);
// Apply custom fields if provided
// Apply custom fields if provided
...
@@ -51,6 +65,7 @@ jQuery.ajaxTransport(function( options ) {
...
@@ -51,6 +65,7 @@ jQuery.ajaxTransport(function( options ) {
callback
=
function
(
type
)
{
callback
=
function
(
type
)
{
return
function
()
{
return
function
()
{
if
(
callback
)
{
if
(
callback
)
{
delete
xhrCallbacks
[
id
];
callback
=
xhr
.
onload
=
xhr
.
onerror
=
null
;
callback
=
xhr
.
onload
=
xhr
.
onerror
=
null
;
if
(
type
===
"abort"
)
{
if
(
type
===
"abort"
)
{
xhr
.
abort
();
xhr
.
abort
();
...
@@ -80,7 +95,7 @@ jQuery.ajaxTransport(function( options ) {
...
@@ -80,7 +95,7 @@ jQuery.ajaxTransport(function( options ) {
xhr
.
onload
=
callback
();
xhr
.
onload
=
callback
();
xhr
.
onerror
=
callback
(
"error"
);
xhr
.
onerror
=
callback
(
"error"
);
// Create the abort callback
// Create the abort callback
callback
=
callback
(
"abort"
);
callback
=
xhrCallbacks
[(
id
=
xhrId
++
)]
=
callback
(
"abort"
);
// Do send the request
// Do send the request
// This may raise an exception which is actually
// This may raise an exception which is actually
// handled in jQuery.ajax (so no try/catch here)
// handled in jQuery.ajax (so no try/catch here)
...
...
test/data/ajax/unreleasedXHR.html
0 → 100644
View file @
62acda81
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta
http-equiv=
"content-type"
content=
"text/html; charset=utf-8"
>
<title>
Attempt to block tests because of dangling XHR requests (IE)
</title>
<script
type=
"text/javascript"
src=
"../../../dist/jquery.js"
></script>
<script
type=
"text/javascript"
>
window
.
onunload
=
function
()
{};
jQuery
(
function
()
{
setTimeout
(
function
()
{
var
parent
=
window
.
parent
;
document
.
write
(
""
);
parent
.
iframeCallback
();
},
200
);
var
number
=
50
;
while
(
number
--
)
{
jQuery
.
ajax
(
"../name.php?wait=600"
);
}
});
</script>
</head>
<body>
<!-- empty body -->
</body>
</html>
test/unit/ajax.js
View file @
62acda81
...
@@ -30,6 +30,11 @@ module( "ajax", {
...
@@ -30,6 +30,11 @@ module( "ajax", {
//----------- jQuery.ajax()
//----------- jQuery.ajax()
testIframeWithCallback
(
"XMLHttpRequest - Attempt to block tests because of dangling XHR requests (IE)"
,
"ajax/unreleasedXHR.html"
,
function
()
{
expect
(
1
);
ok
(
true
,
"done"
);
});
ajaxTest
(
"jQuery.ajax() - success callbacks"
,
8
,
{
ajaxTest
(
"jQuery.ajax() - success callbacks"
,
8
,
{
setup
:
addGlobalEvents
(
"ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"
),
setup
:
addGlobalEvents
(
"ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"
),
url
:
url
(
"data/name.html"
),
url
:
url
(
"data/name.html"
),
...
...
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