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
c5f4d70e
Commit
c5f4d70e
authored
May 15, 2008
by
Ariel Flesler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jqueryjquery ajax: closes #1289. Renamed 'xml' and 'r' to 'xhr'.
parent
82ba3709
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
39 deletions
+39
-39
ajax.js
src/ajax.js
+39
-39
No files found.
src/ajax.js
View file @
c5f4d70e
...
...
@@ -274,51 +274,51 @@ jQuery.extend({
// Create the request object; Microsoft failed to properly
// implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available
var
x
ml
=
window
.
ActiveXObject
?
new
ActiveXObject
(
"Microsoft.XMLHTTP"
)
:
new
XMLHttpRequest
();
var
x
hr
=
window
.
ActiveXObject
?
new
ActiveXObject
(
"Microsoft.XMLHTTP"
)
:
new
XMLHttpRequest
();
// Open the socket
// Passing null username, generates a login popup on Opera (#2865)
if
(
s
.
username
)
x
ml
.
open
(
type
,
s
.
url
,
s
.
async
,
s
.
username
,
s
.
password
);
x
hr
.
open
(
type
,
s
.
url
,
s
.
async
,
s
.
username
,
s
.
password
);
else
x
ml
.
open
(
type
,
s
.
url
,
s
.
async
);
x
hr
.
open
(
type
,
s
.
url
,
s
.
async
);
// Need an extra try/catch for cross domain requests in Firefox 3
try
{
// Set the correct header, if data is being sent
if
(
s
.
data
)
x
ml
.
setRequestHeader
(
"Content-Type"
,
s
.
contentType
);
x
hr
.
setRequestHeader
(
"Content-Type"
,
s
.
contentType
);
// Set the If-Modified-Since header, if ifModified mode.
if
(
s
.
ifModified
)
x
ml
.
setRequestHeader
(
"If-Modified-Since"
,
x
hr
.
setRequestHeader
(
"If-Modified-Since"
,
jQuery
.
lastModified
[
s
.
url
]
||
"Thu, 01 Jan 1970 00:00:00 GMT"
);
// Set header so the called script knows that it's an XMLHttpRequest
x
ml
.
setRequestHeader
(
"X-Requested-With"
,
"XMLHttpRequest"
);
x
hr
.
setRequestHeader
(
"X-Requested-With"
,
"XMLHttpRequest"
);
// Set the Accepts header for the server, depending on the dataType
x
ml
.
setRequestHeader
(
"Accept"
,
s
.
dataType
&&
s
.
accepts
[
s
.
dataType
]
?
x
hr
.
setRequestHeader
(
"Accept"
,
s
.
dataType
&&
s
.
accepts
[
s
.
dataType
]
?
s
.
accepts
[
s
.
dataType
]
+
", */*"
:
s
.
accepts
.
_default
);
}
catch
(
e
){}
// Allow custom headers/mimetypes
if
(
s
.
beforeSend
&&
s
.
beforeSend
(
x
ml
,
s
)
===
false
)
{
if
(
s
.
beforeSend
&&
s
.
beforeSend
(
x
hr
,
s
)
===
false
)
{
// cleanup active request counter
s
.
global
&&
jQuery
.
active
--
;
// close opended socket
x
ml
.
abort
();
x
hr
.
abort
();
return
false
;
}
if
(
s
.
global
)
jQuery
.
event
.
trigger
(
"ajaxSend"
,
[
x
ml
,
s
]);
jQuery
.
event
.
trigger
(
"ajaxSend"
,
[
x
hr
,
s
]);
// Wait for a response to come back
var
onreadystatechange
=
function
(
isTimeout
){
// The transfer is complete and the data is available, or the request timed out
if
(
!
requestDone
&&
x
ml
&&
(
xml
.
readyState
==
4
||
isTimeout
==
"timeout"
)
)
{
if
(
!
requestDone
&&
x
hr
&&
(
xhr
.
readyState
==
4
||
isTimeout
==
"timeout"
)
)
{
requestDone
=
true
;
// clear poll interval
...
...
@@ -328,15 +328,15 @@ jQuery.extend({
}
status
=
isTimeout
==
"timeout"
&&
"timeout"
||
!
jQuery
.
httpSuccess
(
x
ml
)
&&
"error"
||
s
.
ifModified
&&
jQuery
.
httpNotModified
(
x
ml
,
s
.
url
)
&&
"notmodified"
||
!
jQuery
.
httpSuccess
(
x
hr
)
&&
"error"
||
s
.
ifModified
&&
jQuery
.
httpNotModified
(
x
hr
,
s
.
url
)
&&
"notmodified"
||
"success"
;
if
(
status
==
"success"
)
{
// Watch for, and catch, XML document parse errors
try
{
// process the data (runs the xml through httpData regardless of callback)
data
=
jQuery
.
httpData
(
x
ml
,
s
.
dataType
);
data
=
jQuery
.
httpData
(
x
hr
,
s
.
dataType
);
}
catch
(
e
)
{
status
=
"parsererror"
;
}
...
...
@@ -347,7 +347,7 @@ jQuery.extend({
// Cache Last-Modified header, if ifModified mode.
var
modRes
;
try
{
modRes
=
x
ml
.
getResponseHeader
(
"Last-Modified"
);
modRes
=
x
hr
.
getResponseHeader
(
"Last-Modified"
);
}
catch
(
e
)
{}
// swallow exception thrown by FF if header is not available
if
(
s
.
ifModified
&&
modRes
)
...
...
@@ -357,14 +357,14 @@ jQuery.extend({
if
(
!
jsonp
)
success
();
}
else
jQuery
.
handleError
(
s
,
x
ml
,
status
);
jQuery
.
handleError
(
s
,
x
hr
,
status
);
// Fire the complete handlers
complete
();
// Stop memory leaks
if
(
s
.
async
)
x
ml
=
null
;
x
hr
=
null
;
}
};
...
...
@@ -376,9 +376,9 @@ jQuery.extend({
if
(
s
.
timeout
>
0
)
setTimeout
(
function
(){
// Check to see if the request is still happening
if
(
x
ml
)
{
if
(
x
hr
)
{
// Cancel the request
x
ml
.
abort
();
x
hr
.
abort
();
if
(
!
requestDone
)
onreadystatechange
(
"timeout"
);
...
...
@@ -388,9 +388,9 @@ jQuery.extend({
// Send the data
try
{
x
ml
.
send
(
s
.
data
);
x
hr
.
send
(
s
.
data
);
}
catch
(
e
)
{
jQuery
.
handleError
(
s
,
x
ml
,
null
,
e
);
jQuery
.
handleError
(
s
,
x
hr
,
null
,
e
);
}
// firefox 1.5 doesn't fire statechange for sync requests
...
...
@@ -404,17 +404,17 @@ jQuery.extend({
// Fire the global callback
if
(
s
.
global
)
jQuery
.
event
.
trigger
(
"ajaxSuccess"
,
[
x
ml
,
s
]
);
jQuery
.
event
.
trigger
(
"ajaxSuccess"
,
[
x
hr
,
s
]
);
}
function
complete
(){
// Process result
if
(
s
.
complete
)
s
.
complete
(
x
ml
,
status
);
s
.
complete
(
x
hr
,
status
);
// The request was completed
if
(
s
.
global
)
jQuery
.
event
.
trigger
(
"ajaxComplete"
,
[
x
ml
,
s
]
);
jQuery
.
event
.
trigger
(
"ajaxComplete"
,
[
x
hr
,
s
]
);
// Handle the global AJAX counter
if
(
s
.
global
&&
!
--
jQuery
.
active
)
...
...
@@ -422,48 +422,48 @@ jQuery.extend({
}
// return XMLHttpRequest to allow aborting the request etc.
return
x
ml
;
return
x
hr
;
},
handleError
:
function
(
s
,
x
ml
,
status
,
e
)
{
handleError
:
function
(
s
,
x
hr
,
status
,
e
)
{
// If a local callback was specified, fire it
if
(
s
.
error
)
s
.
error
(
x
ml
,
status
,
e
);
if
(
s
.
error
)
s
.
error
(
x
hr
,
status
,
e
);
// Fire the global callback
if
(
s
.
global
)
jQuery
.
event
.
trigger
(
"ajaxError"
,
[
x
ml
,
s
,
e
]
);
jQuery
.
event
.
trigger
(
"ajaxError"
,
[
x
hr
,
s
,
e
]
);
},
// Counter for holding the number of active queries
active
:
0
,
// Determines if an XMLHttpRequest was successful or not
httpSuccess
:
function
(
r
)
{
httpSuccess
:
function
(
xh
r
)
{
try
{
// IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
return
!
r
.
status
&&
location
.
protocol
==
"file:"
||
(
r
.
status
>=
200
&&
r
.
status
<
300
)
||
r
.
status
==
304
||
r
.
status
==
1223
||
jQuery
.
browser
.
safari
&&
r
.
status
==
undefined
;
return
!
xh
r
.
status
&&
location
.
protocol
==
"file:"
||
(
xhr
.
status
>=
200
&&
xhr
.
status
<
300
)
||
xhr
.
status
==
304
||
xh
r
.
status
==
1223
||
jQuery
.
browser
.
safari
&&
xh
r
.
status
==
undefined
;
}
catch
(
e
){}
return
false
;
},
// Determines if an XMLHttpRequest returns NotModified
httpNotModified
:
function
(
x
ml
,
url
)
{
httpNotModified
:
function
(
x
hr
,
url
)
{
try
{
var
x
mlRes
=
xml
.
getResponseHeader
(
"Last-Modified"
);
var
x
hrRes
=
xhr
.
getResponseHeader
(
"Last-Modified"
);
// Firefox always returns 200. check Last-Modified date
return
x
ml
.
status
==
304
||
xml
Res
==
jQuery
.
lastModified
[
url
]
||
jQuery
.
browser
.
safari
&&
x
ml
.
status
==
undefined
;
return
x
hr
.
status
==
304
||
xhr
Res
==
jQuery
.
lastModified
[
url
]
||
jQuery
.
browser
.
safari
&&
x
hr
.
status
==
undefined
;
}
catch
(
e
){}
return
false
;
},
httpData
:
function
(
r
,
type
)
{
var
ct
=
r
.
getResponseHeader
(
"content-type"
),
httpData
:
function
(
xh
r
,
type
)
{
var
ct
=
xh
r
.
getResponseHeader
(
"content-type"
),
xml
=
type
==
"xml"
||
!
type
&&
ct
&&
ct
.
indexOf
(
"xml"
)
>=
0
,
data
=
xml
?
r
.
responseXML
:
r
.
responseText
;
data
=
xml
?
xhr
.
responseXML
:
xh
r
.
responseText
;
if
(
xml
&&
data
.
documentElement
.
tagName
==
"parsererror"
)
throw
"parsererror"
;
...
...
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