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
6344821f
Commit
6344821f
authored
Jan 26, 2011
by
jeresig
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:jquery/jquery
parents
2c290709
bab80795
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
51 deletions
+88
-51
ajax.js
src/ajax.js
+29
-22
jsonp.js
src/ajax/jsonp.js
+1
-1
xhr.js
src/ajax/xhr.js
+3
-6
core.js
src/core.js
+0
-3
ajax.js
test/unit/ajax.js
+55
-19
No files found.
src/ajax.js
View file @
6344821f
...
@@ -7,15 +7,13 @@ var r20 = /%20/g,
...
@@ -7,15 +7,13 @@ var r20 = /%20/g,
rheaders
=
/^
(
.*
?)
:
\s
*
(
.*
?)\r?
$/mg
,
// IE leaves an \r character at EOL
rheaders
=
/^
(
.*
?)
:
\s
*
(
.*
?)\r?
$/mg
,
// IE leaves an \r character at EOL
rinput
=
/^
(?:
color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week
)
$/i
,
rinput
=
/^
(?:
color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week
)
$/i
,
rnoContent
=
/^
(?:
GET|HEAD
)
$/
,
rnoContent
=
/^
(?:
GET|HEAD
)
$/
,
rprotocol
=
/^
\/\/
/
,
rquery
=
/
\?
/
,
rquery
=
/
\?
/
,
rscript
=
/<script
\b[^
<
]
*
(?:(?!
<
\/
script>
)
<
[^
<
]
*
)
*<
\/
script>/gi
,
rscript
=
/<script
\b[^
<
]
*
(?:(?!
<
\/
script>
)
<
[^
<
]
*
)
*<
\/
script>/gi
,
rselectTextarea
=
/^
(?:
select|textarea
)
/i
,
rselectTextarea
=
/^
(?:
select|textarea
)
/i
,
rspacesAjax
=
/
\s
+/
,
rspacesAjax
=
/
\s
+/
,
rts
=
/
([
?&
])
_=
[^
&
]
*/
,
rts
=
/
([
?&
])
_=
[^
&
]
*/
,
rurl
=
/^
(\w
+:
)?\/\/([^\/
?#:
]
+
)(?:
:
(\d
+
))?
/
,
rurl
=
/^
(\w
+:
)\/\/([^\/
?#:
]
+
)(?:
:
(\d
+
))?
/
,
// Slice function
sliceFunc
=
Array
.
prototype
.
slice
,
// Keep a copy of the old load method
// Keep a copy of the old load method
_load
=
jQuery
.
fn
.
load
,
_load
=
jQuery
.
fn
.
load
,
...
@@ -75,7 +73,7 @@ function addToPrefiltersOrTransports( structure ) {
...
@@ -75,7 +73,7 @@ function addToPrefiltersOrTransports( structure ) {
}
}
//Base inspection function for prefilters and transports
//Base inspection function for prefilters and transports
function
inspectPrefiltersOrTransports
(
structure
,
options
,
originalOptions
,
function
inspectPrefiltersOrTransports
(
structure
,
options
,
originalOptions
,
jXHR
,
dataType
/* internal */
,
inspected
/* internal */
)
{
dataType
/* internal */
,
inspected
/* internal */
)
{
dataType
=
dataType
||
options
.
dataTypes
[
0
];
dataType
=
dataType
||
options
.
dataTypes
[
0
];
...
@@ -99,7 +97,7 @@ function inspectPrefiltersOrTransports( structure, options, originalOptions,
...
@@ -99,7 +97,7 @@ function inspectPrefiltersOrTransports( structure, options, originalOptions,
}
else
{
}
else
{
options
.
dataTypes
.
unshift
(
selection
);
options
.
dataTypes
.
unshift
(
selection
);
selection
=
inspectPrefiltersOrTransports
(
selection
=
inspectPrefiltersOrTransports
(
structure
,
options
,
originalOptions
,
selection
,
inspected
);
structure
,
options
,
originalOptions
,
jXHR
,
selection
,
inspected
);
}
}
}
}
}
}
...
@@ -107,7 +105,7 @@ function inspectPrefiltersOrTransports( structure, options, originalOptions,
...
@@ -107,7 +105,7 @@ function inspectPrefiltersOrTransports( structure, options, originalOptions,
// we try the catchall dataType if not done already
// we try the catchall dataType if not done already
if
(
(
executeOnly
||
!
selection
)
&&
!
inspected
[
"*"
]
)
{
if
(
(
executeOnly
||
!
selection
)
&&
!
inspected
[
"*"
]
)
{
selection
=
inspectPrefiltersOrTransports
(
selection
=
inspectPrefiltersOrTransports
(
structure
,
options
,
originalOptions
,
"*"
,
inspected
);
structure
,
options
,
originalOptions
,
jXHR
,
"*"
,
inspected
);
}
}
// unnecessary when only executing (prefilters)
// unnecessary when only executing (prefilters)
// but it'll be ignored by the caller in that case
// but it'll be ignored by the caller in that case
...
@@ -400,8 +398,9 @@ jQuery.extend({
...
@@ -400,8 +398,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 +437,7 @@ jQuery.extend({
...
@@ -438,7 +437,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 +475,16 @@ jQuery.extend({
...
@@ -476,6 +475,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
...
@@ -533,8 +542,9 @@ jQuery.extend({
...
@@ -533,8 +542,9 @@ jQuery.extend({
};
};
// Remove hash character (#7531: and string promotion)
// Remove hash character (#7531: and string promotion)
// Add protocol if not provided (#5866: IE7 issue with protocol-less urls)
// We also use the url parameter if available
// We also use the url parameter if available
s
.
url
=
(
""
+
(
url
||
s
.
url
)
).
replace
(
rhash
,
""
);
s
.
url
=
(
""
+
(
url
||
s
.
url
)
).
replace
(
rhash
,
""
)
.
replace
(
rprotocol
,
protocol
+
"//"
)
;
// Extract dataTypes list
// Extract dataTypes list
s
.
dataTypes
=
jQuery
.
trim
(
s
.
dataType
||
"*"
).
toLowerCase
().
split
(
rspacesAjax
);
s
.
dataTypes
=
jQuery
.
trim
(
s
.
dataType
||
"*"
).
toLowerCase
().
split
(
rspacesAjax
);
...
@@ -542,12 +552,10 @@ jQuery.extend({
...
@@ -542,12 +552,10 @@ jQuery.extend({
// Determine if a cross-domain request is in order
// Determine if a cross-domain request is in order
if
(
!
s
.
crossDomain
)
{
if
(
!
s
.
crossDomain
)
{
parts
=
rurl
.
exec
(
s
.
url
.
toLowerCase
()
);
parts
=
rurl
.
exec
(
s
.
url
.
toLowerCase
()
);
s
.
crossDomain
=
!!
(
s
.
crossDomain
=
!!
(
parts
&&
parts
&&
(
parts
[
1
]
!=
protocol
||
parts
[
2
]
!=
loc
.
hostname
||
(
parts
[
1
]
&&
parts
[
1
]
!=
protocol
||
(
parts
[
3
]
||
(
parts
[
1
]
===
"http:"
?
80
:
443
)
)
!=
parts
[
2
]
!=
loc
.
hostname
||
(
loc
.
port
||
(
protocol
===
"http:"
?
80
:
443
)
)
)
(
parts
[
3
]
||
(
(
parts
[
1
]
||
protocol
)
===
"http:"
?
80
:
443
)
)
!=
(
loc
.
port
||
(
protocol
===
"http:"
?
80
:
443
)
)
)
);
);
}
}
...
@@ -557,7 +565,7 @@ jQuery.extend({
...
@@ -557,7 +565,7 @@ jQuery.extend({
}
}
// Apply prefilters
// Apply prefilters
inspectPrefiltersOrTransports
(
prefilters
,
s
,
options
);
inspectPrefiltersOrTransports
(
prefilters
,
s
,
options
,
jXHR
);
// Uppercase the type
// Uppercase the type
s
.
type
=
s
.
type
.
toUpperCase
();
s
.
type
=
s
.
type
.
toUpperCase
();
...
@@ -630,11 +638,11 @@ jQuery.extend({
...
@@ -630,11 +638,11 @@ jQuery.extend({
}
}
// Get transport
// Get transport
transport
=
inspectPrefiltersOrTransports
(
transports
,
s
,
options
);
transport
=
inspectPrefiltersOrTransports
(
transports
,
s
,
options
,
jXHR
);
// 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 +661,8 @@ jQuery.extend({
...
@@ -653,9 +661,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/jsonp.js
View file @
6344821f
(
function
(
jQuery
)
{
(
function
(
jQuery
)
{
var
jsc
=
jQuery
.
now
(),
var
jsc
=
jQuery
.
now
(),
jsre
=
/
(\=)
(?:\?
|%3F
)(
&|$
)
|
()(?:\?\?
|%3F%3F
)
()
/i
;
jsre
=
/
(\=)
\?(
&|$
)
|
()\?\?
()
/i
;
// Default jsonp settings
// Default jsonp settings
jQuery
.
ajaxSetup
({
jQuery
.
ajaxSetup
({
...
...
src/ajax/xhr.js
View file @
6344821f
...
@@ -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
)
{
...
...
src/core.js
View file @
6344821f
...
@@ -26,9 +26,6 @@ var jQuery = function( selector, context ) {
...
@@ -26,9 +26,6 @@ var jQuery = function( selector, context ) {
trimLeft
=
/^
\s
+/
,
trimLeft
=
/^
\s
+/
,
trimRight
=
/
\s
+$/
,
trimRight
=
/
\s
+$/
,
// Check for non-word characters
rnonword
=
/
\W
/
,
// Check for digits
// Check for digits
rdigit
=
/
\d
/
,
rdigit
=
/
\d
/
,
...
...
test/unit/ajax.js
View file @
6344821f
...
@@ -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
);
...
@@ -374,6 +415,18 @@ test(".ajax() - contentType" , function() {
...
@@ -374,6 +415,18 @@ test(".ajax() - contentType" , function() {
});
});
test
(
".ajax() - protocol-less urls"
,
function
()
{
expect
(
1
);
jQuery
.
ajax
({
url
:
"//somedomain.com"
,
beforeSend
:
function
(
xhr
,
settings
)
{
equals
(
settings
.
url
,
location
.
protocol
+
"//somedomain.com"
,
"Make sure that the protocol is added."
);
return
false
;
}
});
});
test
(
".ajax() - hash"
,
function
()
{
test
(
".ajax() - hash"
,
function
()
{
expect
(
3
);
expect
(
3
);
...
@@ -1158,10 +1211,10 @@ test("jQuery.getScript(String, Function) - no callback", function() {
...
@@ -1158,10 +1211,10 @@ test("jQuery.getScript(String, Function) - no callback", function() {
jQuery
.
each
(
[
"Same Domain"
,
"Cross Domain"
]
,
function
(
crossDomain
,
label
)
{
jQuery
.
each
(
[
"Same Domain"
,
"Cross Domain"
]
,
function
(
crossDomain
,
label
)
{
test
(
"jQuery.ajax() - JSONP, "
+
label
,
function
()
{
test
(
"jQuery.ajax() - JSONP, "
+
label
,
function
()
{
expect
(
1
7
);
expect
(
1
6
);
var
count
=
0
;
var
count
=
0
;
function
plus
(){
if
(
++
count
==
1
7
)
start
();
}
function
plus
(){
if
(
++
count
==
1
6
)
start
();
}
stop
();
stop
();
...
@@ -1265,23 +1318,6 @@ jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label )
...
@@ -1265,23 +1318,6 @@ jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label )
}
}
});
});
jQuery
.
ajax
({
url
:
"data/jsonp.php"
,
dataType
:
"jsonp"
,
crossDomain
:
crossDomain
,
data
:
{
callback
:
"?"
},
success
:
function
(
data
){
ok
(
data
.
data
,
"JSON results returned (GET, processed data callback)"
);
plus
();
},
error
:
function
(
data
){
ok
(
false
,
"Ajax error JSON (GET, processed data callback)"
);
plus
();
}
});
jQuery
.
ajax
({
jQuery
.
ajax
({
url
:
"data/jsonp.php"
,
url
:
"data/jsonp.php"
,
dataType
:
"jsonp"
,
dataType
:
"jsonp"
,
...
...
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