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
5ca8f061
Commit
5ca8f061
authored
Jan 25, 2011
by
jaubourg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reworks how values of parameters passed to error callbacks are determined. Fixes #8050.
parent
8d050558
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
12 deletions
+60
-12
ajax.js
src/ajax.js
+16
-6
xhr.js
src/ajax/xhr.js
+3
-6
ajax.js
test/unit/ajax.js
+41
-0
No files found.
src/ajax.js
View file @
5ca8f061
...
@@ -400,8 +400,9 @@ jQuery.extend({
...
@@ -400,8 +400,9 @@ jQuery.extend({
// Cancel the request
// Cancel the request
abort
:
function
(
statusText
)
{
abort
:
function
(
statusText
)
{
statusText
=
statusText
||
"abort"
;
if
(
transport
)
{
if
(
transport
)
{
transport
.
abort
(
statusText
||
"abort"
);
transport
.
abort
(
statusText
);
}
}
done
(
0
,
statusText
);
done
(
0
,
statusText
);
return
this
;
return
this
;
...
@@ -438,7 +439,7 @@ jQuery.extend({
...
@@ -438,7 +439,7 @@ jQuery.extend({
var
isSuccess
,
var
isSuccess
,
success
,
success
,
error
=
(
statusText
=
statusText
||
"error"
)
,
error
,
response
=
responses
?
ajaxHandleResponses
(
s
,
jXHR
,
responses
)
:
undefined
,
response
=
responses
?
ajaxHandleResponses
(
s
,
jXHR
,
responses
)
:
undefined
,
lastModified
,
lastModified
,
etag
;
etag
;
...
@@ -476,6 +477,16 @@ jQuery.extend({
...
@@ -476,6 +477,16 @@ jQuery.extend({
error
=
""
+
e
;
error
=
""
+
e
;
}
}
}
}
}
else
{
// We extract error from statusText
// then normalize statusText and status for non-aborts
error
=
statusText
;
if
(
status
)
{
statusText
=
"error"
;
if
(
status
<
0
)
{
status
=
0
;
}
}
}
}
// Set data for the fake xhr object
// Set data for the fake xhr object
...
@@ -634,7 +645,7 @@ jQuery.extend({
...
@@ -634,7 +645,7 @@ jQuery.extend({
// If no transport, we auto-abort
// If no transport, we auto-abort
if
(
!
transport
)
{
if
(
!
transport
)
{
done
(
0
,
"not
ransport"
);
done
(
-
1
,
"No T
ransport"
);
}
else
{
}
else
{
// Set state as sending
// Set state as sending
state
=
jXHR
.
readyState
=
1
;
state
=
jXHR
.
readyState
=
1
;
...
@@ -653,9 +664,8 @@ jQuery.extend({
...
@@ -653,9 +664,8 @@ jQuery.extend({
transport
.
send
(
requestHeaders
,
done
);
transport
.
send
(
requestHeaders
,
done
);
}
catch
(
e
)
{
}
catch
(
e
)
{
// Propagate exception as error if not done
// Propagate exception as error if not done
if
(
status
===
1
)
{
if
(
status
<
2
)
{
done
(
0
,
"error"
,
""
+
e
);
done
(
-
1
,
""
+
e
);
jXHR
=
false
;
// Simply rethrow otherwise
// Simply rethrow otherwise
}
else
{
}
else
{
jQuery
.
error
(
e
);
jQuery
.
error
(
e
);
...
...
src/ajax/xhr.js
View file @
5ca8f061
...
@@ -108,12 +108,9 @@ if ( jQuery.support.ajax ) {
...
@@ -108,12 +108,9 @@ if ( jQuery.support.ajax ) {
}
catch
(
_
)
{}
}
catch
(
_
)
{}
// Do send the request
// Do send the request
try
{
// This may raise an exception which is actually
xhr
.
send
(
(
s
.
hasContent
&&
s
.
data
)
||
null
);
// handled in jQuery.ajax (so no try/catch here)
}
catch
(
e
)
{
xhr
.
send
(
(
s
.
hasContent
&&
s
.
data
)
||
null
);
complete
(
0
,
"error"
,
""
+
e
);
return
;
}
// Listener
// Listener
callback
=
function
(
_
,
isAbort
)
{
callback
=
function
(
_
,
isAbort
)
{
...
...
test/unit/ajax.js
View file @
5ca8f061
...
@@ -240,6 +240,47 @@ test("jQuery.ajax() - error callbacks", function() {
...
@@ -240,6 +240,47 @@ test("jQuery.ajax() - error callbacks", function() {
});
});
});
});
test
(
"jQuery.ajax() - textStatus and errorThrown values"
,
function
()
{
var
nb
=
3
;
expect
(
2
*
nb
);
stop
();
function
startN
()
{
if
(
!
(
--
nb
)
)
{
start
();
}
}
jQuery
.
ajax
({
url
:
url
(
"data/nonExistingURL"
),
error
:
function
(
_
,
textStatus
,
errorThrown
){
strictEqual
(
textStatus
,
"error"
,
"textStatus is 'error' for 404"
);
strictEqual
(
errorThrown
,
"Not Found"
,
"errorThrown is 'Not Found' for 404"
);
startN
();
}
});
jQuery
.
ajax
({
url
:
url
(
"data/name.php?wait=5"
),
error
:
function
(
_
,
textStatus
,
errorThrown
){
strictEqual
(
textStatus
,
"abort"
,
"textStatus is 'abort' for abort"
);
strictEqual
(
errorThrown
,
"abort"
,
"errorThrown is 'abort' for abort"
);
startN
();
}
}).
abort
();
jQuery
.
ajax
({
url
:
url
(
"data/name.php?wait=5"
),
error
:
function
(
_
,
textStatus
,
errorThrown
){
strictEqual
(
textStatus
,
"mystatus"
,
"textStatus is 'mystatus' for abort('mystatus')"
);
strictEqual
(
errorThrown
,
"mystatus"
,
"errorThrown is 'mystatus' for abort('mystatus')"
);
startN
();
}
}).
abort
(
"mystatus"
);
});
test
(
"jQuery.ajax() - responseText on error"
,
function
()
{
test
(
"jQuery.ajax() - responseText on error"
,
function
()
{
expect
(
1
);
expect
(
1
);
...
...
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