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
ea5ce8c2
Commit
ea5ce8c2
authored
Jan 20, 2011
by
jeresig
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:jquery/jquery
parents
e4d01688
f2b0c77d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
52 deletions
+78
-52
ajax.js
src/ajax.js
+28
-30
xhr.js
src/ajax/xhr.js
+12
-11
core.js
src/core.js
+7
-7
ajax.js
test/unit/ajax.js
+30
-3
core.js
test/unit/core.js
+1
-1
No files found.
src/ajax.js
View file @
ea5ce8c2
...
@@ -235,7 +235,7 @@ jQuery.extend({
...
@@ -235,7 +235,7 @@ jQuery.extend({
// Utility function that handles dataType when response is received
// Utility function that handles dataType when response is received
// (for those transports that can give text or xml responses)
// (for those transports that can give text or xml responses)
determine
DataType
:
function
(
ct
,
text
,
xml
)
{
determine
Response
:
function
(
responses
,
ct
)
{
var
s
=
this
,
var
s
=
this
,
contents
=
s
.
contents
,
contents
=
s
.
contents
,
...
@@ -246,7 +246,7 @@ jQuery.extend({
...
@@ -246,7 +246,7 @@ jQuery.extend({
response
;
response
;
// Auto (xml, json, script or text determined given headers)
// Auto (xml, json, script or text determined given headers)
if
(
transportDataType
===
"*"
)
{
if
(
ct
&&
transportDataType
===
"*"
)
{
for
(
type
in
contents
)
{
for
(
type
in
contents
)
{
if
(
(
regexp
=
contents
[
type
]
)
&&
regexp
.
test
(
ct
)
)
{
if
(
(
regexp
=
contents
[
type
]
)
&&
regexp
.
test
(
ct
)
)
{
...
@@ -256,23 +256,22 @@ jQuery.extend({
...
@@ -256,23 +256,22 @@ jQuery.extend({
}
}
}
}
// xml and parsed as such
// Get response
if
(
transportDataType
===
"xml"
&&
for
(
type
in
responses
)
{
xml
&&
if
(
type
===
transportDataType
)
{
xml
.
documentElement
/* #4958 */
)
{
break
;
}
response
=
xml
;
}
// Text response was provided
}
else
{
response
=
text
;
// Get final response
response
=
responses
[
type
];
// If it's not really text, defer to converters
// If it's not the right dataType, handle the dataTypeList
if
(
transportDataType
!==
"text"
)
{
if
(
transportDataType
!==
type
)
{
dataTypes
.
unshift
(
"text"
);
if
(
transportDataType
===
"*"
)
{
dataTypes
.
shift
();
}
}
dataTypes
.
unshift
(
type
);
}
}
return
response
;
return
response
;
...
@@ -291,18 +290,16 @@ jQuery.extend({
...
@@ -291,18 +290,16 @@ jQuery.extend({
// Main method
// Main method
ajax
:
function
(
url
,
options
)
{
ajax
:
function
(
url
,
options
)
{
// Handle varargs
// If options is not an object,
if
(
arguments
.
length
===
1
)
{
// we simulate pre-1.5 signature
if
(
typeof
(
options
)
!==
"object"
)
{
options
=
url
;
options
=
url
;
url
=
options
?
options
.
url
:
undefined
;
url
=
undefined
;
}
}
// Force options to be an object
// Force options to be an object
options
=
options
||
{};
options
=
options
||
{};
// Get the url if provided separately
options
.
url
=
url
||
options
.
url
;
var
// Create the final options object
var
// Create the final options object
s
=
jQuery
.
extend
(
true
,
{}
,
jQuery
.
ajaxSettings
,
options
),
s
=
jQuery
.
extend
(
true
,
{}
,
jQuery
.
ajaxSettings
,
options
),
// jQuery lists
// jQuery lists
...
@@ -427,10 +424,8 @@ jQuery.extend({
...
@@ -427,10 +424,8 @@ jQuery.extend({
// Stored error
// Stored error
error
,
error
,
// Keep track of statusCode callbacks
// To keep track of statusCode based callbacks
oldStatusCode
=
statusCode
;
oldStatusCode
;
statusCode
=
undefined
;
// If successful, handle type chaining
// If successful, handle type chaining
if
(
status
>=
200
&&
status
<
300
||
status
===
304
)
{
if
(
status
>=
200
&&
status
<
300
||
status
===
304
)
{
...
@@ -582,12 +577,14 @@ jQuery.extend({
...
@@ -582,12 +577,14 @@ jQuery.extend({
// Success/Error
// Success/Error
if
(
isSuccess
)
{
if
(
isSuccess
)
{
deferred
.
fire
(
callbackContext
,
[
success
,
statusText
,
jXHR
]
);
deferred
.
resolveWith
(
callbackContext
,
[
success
,
statusText
,
jXHR
]
);
}
else
{
}
else
{
deferred
.
fireReject
(
callbackContext
,
[
jXHR
,
statusText
,
error
]
);
deferred
.
rejectWith
(
callbackContext
,
[
jXHR
,
statusText
,
error
]
);
}
}
// Status-dependent callbacks
// Status-dependent callbacks
oldStatusCode
=
statusCode
;
statusCode
=
undefined
;
jXHR
.
statusCode
(
oldStatusCode
);
jXHR
.
statusCode
(
oldStatusCode
);
if
(
s
.
global
)
{
if
(
s
.
global
)
{
...
@@ -596,7 +593,7 @@ jQuery.extend({
...
@@ -596,7 +593,7 @@ jQuery.extend({
}
}
// Complete
// Complete
completeDeferred
.
fire
(
callbackContext
,
[
jXHR
,
statusText
]
);
completeDeferred
.
resolveWith
(
callbackContext
,
[
jXHR
,
statusText
]
);
if
(
s
.
global
)
{
if
(
s
.
global
)
{
globalEventContext
.
trigger
(
"ajaxComplete"
,
[
jXHR
,
s
]
);
globalEventContext
.
trigger
(
"ajaxComplete"
,
[
jXHR
,
s
]
);
...
@@ -630,7 +627,8 @@ jQuery.extend({
...
@@ -630,7 +627,8 @@ jQuery.extend({
};
};
// Remove hash character (#7531: and string promotion)
// Remove hash character (#7531: and string promotion)
s
.
url
=
(
""
+
s
.
url
).
replace
(
rhash
,
""
);
// We also use the url parameter if available
s
.
url
=
(
""
+
(
url
||
s
.
url
)
).
replace
(
rhash
,
""
);
// Extract dataTypes list
// Extract dataTypes list
s
.
dataTypes
=
jQuery
.
trim
(
s
.
dataType
||
"*"
).
toLowerCase
().
split
(
/
\s
+/
);
s
.
dataTypes
=
jQuery
.
trim
(
s
.
dataType
||
"*"
).
toLowerCase
().
split
(
/
\s
+/
);
...
...
src/ajax/xhr.js
View file @
ea5ce8c2
...
@@ -12,8 +12,8 @@ var // Next active xhr id
...
@@ -12,8 +12,8 @@ var // Next active xhr id
// XHR used to determine supports properties
// XHR used to determine supports properties
testXHR
;
testXHR
;
// Create the request object
; Microsoft failed to properly
// Create the request object
// (This is still attached to ajaxSettings for backward compatibility
reasons
)
// (This is still attached to ajaxSettings for backward compatibility)
jQuery
.
ajaxSettings
.
xhr
=
window
.
ActiveXObject
?
jQuery
.
ajaxSettings
.
xhr
=
window
.
ActiveXObject
?
/* Microsoft failed to properly
/* Microsoft failed to properly
* implement the XMLHttpRequest in IE7 (can't request local files),
* implement the XMLHttpRequest in IE7 (can't request local files),
...
@@ -146,8 +146,9 @@ if ( jQuery.support.ajax ) {
...
@@ -146,8 +146,9 @@ if ( jQuery.support.ajax ) {
// Get info
// Get info
var
status
=
xhr
.
status
,
var
status
=
xhr
.
status
,
statusText
,
statusText
,
response
,
responseHeaders
=
xhr
.
getAllResponseHeaders
(),
responseHeaders
=
xhr
.
getAllResponseHeaders
();
responses
=
{},
xml
=
xhr
.
responseXML
;
try
{
// Firefox throws an exception when accessing statusText for faulty cross-domain requests
try
{
// Firefox throws an exception when accessing statusText for faulty cross-domain requests
...
@@ -184,15 +185,15 @@ if ( jQuery.support.ajax ) {
...
@@ -184,15 +185,15 @@ if ( jQuery.support.ajax ) {
status
status
);
);
// Guess response & update dataType accordingly
// Construct response list
response
=
if
(
xml
&&
xml
.
documentElement
/* #4958 */
)
{
s
.
determineDataType
(
responses
.
xml
=
xml
;
xhr
.
getResponseHeader
(
"content-type"
),
}
xhr
.
responseText
,
responses
.
text
=
xhr
.
responseText
;
xhr
.
responseXML
);
// Call complete
// Call complete
complete
(
status
,
statusText
,
response
,
responseHeaders
);
complete
(
status
,
statusText
,
s
.
determineResponse
(
responses
,
xhr
.
getResponseHeader
(
"content-type"
)
),
responseHeaders
);
}
}
}
}
};
};
...
...
src/core.js
View file @
ea5ce8c2
...
@@ -399,7 +399,7 @@ jQuery.extend({
...
@@ -399,7 +399,7 @@ jQuery.extend({
}
}
// If there are functions bound, to execute
// If there are functions bound, to execute
readyList
.
fire
(
document
,
[
jQuery
]
);
readyList
.
resolveWith
(
document
,
[
jQuery
]
);
// Trigger any bound ready events
// Trigger any bound ready events
if
(
jQuery
.
fn
.
trigger
)
{
if
(
jQuery
.
fn
.
trigger
)
{
...
@@ -837,7 +837,7 @@ jQuery.extend({
...
@@ -837,7 +837,7 @@ jQuery.extend({
}
}
if
(
_fired
)
{
if
(
_fired
)
{
deferred
.
fire
(
_fired
[
0
]
,
_fired
[
1
]
);
deferred
.
resolveWith
(
_fired
[
0
]
,
_fired
[
1
]
);
}
}
}
}
...
@@ -845,7 +845,7 @@ jQuery.extend({
...
@@ -845,7 +845,7 @@ jQuery.extend({
},
},
// resolve with given context and args
// resolve with given context and args
fire
:
function
(
context
,
args
)
{
resolveWith
:
function
(
context
,
args
)
{
if
(
!
cancelled
&&
!
fired
&&
!
firing
)
{
if
(
!
cancelled
&&
!
fired
&&
!
firing
)
{
firing
=
1
;
firing
=
1
;
...
@@ -865,7 +865,7 @@ jQuery.extend({
...
@@ -865,7 +865,7 @@ jQuery.extend({
// resolve with this as context and given arguments
// resolve with this as context and given arguments
resolve
:
function
()
{
resolve
:
function
()
{
deferred
.
fire
(
jQuery
.
isFunction
(
this
.
promise
)
?
this
.
promise
()
:
this
,
arguments
);
deferred
.
resolveWith
(
jQuery
.
isFunction
(
this
.
promise
)
?
this
.
promise
()
:
this
,
arguments
);
return
this
;
return
this
;
},
},
...
@@ -901,7 +901,7 @@ jQuery.extend({
...
@@ -901,7 +901,7 @@ jQuery.extend({
return
this
;
return
this
;
},
},
fail
:
failDeferred
.
done
,
fail
:
failDeferred
.
done
,
fireReject
:
failDeferred
.
fire
,
rejectWith
:
failDeferred
.
resolveWith
,
reject
:
failDeferred
.
resolve
,
reject
:
failDeferred
.
resolve
,
isRejected
:
failDeferred
.
isResolved
,
isRejected
:
failDeferred
.
isResolved
,
// Get a promise for this deferred
// Get a promise for this deferred
...
@@ -954,10 +954,10 @@ jQuery.extend({
...
@@ -954,10 +954,10 @@ jQuery.extend({
args
=
arguments
;
args
=
arguments
;
resolveArray
[
index
]
=
args
.
length
>
1
?
slice
.
call
(
args
,
0
)
:
value
;
resolveArray
[
index
]
=
args
.
length
>
1
?
slice
.
call
(
args
,
0
)
:
value
;
if
(
!
--
length
)
{
if
(
!
--
length
)
{
deferred
.
fire
(
promise
,
resolveArray
);
deferred
.
resolveWith
(
promise
,
resolveArray
);
}
}
}).
fail
(
function
()
{
}).
fail
(
function
()
{
deferred
.
fireReject
(
promise
,
arguments
);
deferred
.
rejectWith
(
promise
,
arguments
);
});
});
return
!
deferred
.
isRejected
();
return
!
deferred
.
isRejected
();
});
});
...
...
test/unit/ajax.js
View file @
ea5ce8c2
...
@@ -1911,9 +1911,9 @@ test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
...
@@ -1911,9 +1911,9 @@ test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
test
(
"jQuery.ajax - statusCode"
,
function
()
{
test
(
"jQuery.ajax - statusCode"
,
function
()
{
var
count
=
1
0
;
var
count
=
1
2
;
expect
(
16
);
expect
(
20
);
stop
();
stop
();
function
countComplete
()
{
function
countComplete
()
{
...
@@ -1975,8 +1975,35 @@ test( "jQuery.ajax - statusCode" , function() {
...
@@ -1975,8 +1975,35 @@ test( "jQuery.ajax - statusCode" , function() {
}
}
}).
statusCode
(
createStatusCodes
(
"all (immediately with method)"
,
isSuccess
)
);
}).
statusCode
(
createStatusCodes
(
"all (immediately with method)"
,
isSuccess
)
);
});
var
testString
=
""
;
jQuery
.
ajax
(
url
(
uri
),
{
success
:
function
(
a
,
b
,
jXHR
)
{
ok
(
isSuccess
,
"success"
);
var
statusCode
=
{};
statusCode
[
jXHR
.
status
]
=
function
()
{
testString
+=
"B"
;
};
jXHR
.
statusCode
(
statusCode
);
testString
+=
"A"
;
},
error
:
function
(
jXHR
)
{
ok
(
!
isSuccess
,
"error"
);
var
statusCode
=
{};
statusCode
[
jXHR
.
status
]
=
function
()
{
testString
+=
"B"
;
};
jXHR
.
statusCode
(
statusCode
);
testString
+=
"A"
;
},
complete
:
function
()
{
strictEqual
(
testString
,
"AB"
,
"Test statusCode callbacks are ordered like "
+
(
isSuccess
?
"success"
:
"error"
)
+
" callbacks"
);
countComplete
();
}
}
);
});
});
});
test
(
"jQuery.ajax - active counter"
,
function
()
{
test
(
"jQuery.ajax - active counter"
,
function
()
{
...
...
test/unit/core.js
View file @
ea5ce8c2
...
@@ -1002,7 +1002,7 @@ test("jQuery._Deferred()", function() {
...
@@ -1002,7 +1002,7 @@ test("jQuery._Deferred()", function() {
deferred
=
jQuery
.
_Deferred
();
deferred
=
jQuery
.
_Deferred
();
deferred
.
fire
(
jQuery
,
[
document
]
).
done
(
function
(
doc
)
{
deferred
.
resolveWith
(
jQuery
,
[
document
]
).
done
(
function
(
doc
)
{
ok
(
this
===
jQuery
&&
arguments
.
length
===
1
&&
doc
===
document
,
"Test fire context & args"
);
ok
(
this
===
jQuery
&&
arguments
.
length
===
1
&&
doc
===
document
,
"Test fire context & args"
);
});
});
});
});
...
...
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