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
3a1d7a3c
Commit
3a1d7a3c
authored
Feb 11, 2011
by
jaubourg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplifies status normalization in xhr transport. Local file test modified for clarity.
parent
43a41ba7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
44 deletions
+37
-44
xhr.js
src/ajax/xhr.js
+8
-29
localfile.html
test/localfile.html
+29
-15
No files found.
src/ajax/xhr.js
View file @
3a1d7a3c
...
@@ -166,35 +166,14 @@ if ( jQuery.support.ajax ) {
...
@@ -166,35 +166,14 @@ if ( jQuery.support.ajax ) {
}
}
// Filter status for non standard behaviors
// Filter status for non standard behaviors
status
=
// IE - #1450: sometimes returns 1223 when it should be 204
// If the request is local and we have data: assume a success
if
(
status
===
1223
)
{
// (success with no data won't get notified, that's the best we
status
=
204
;
// can do given current implementations)
// Various - #8177: a Not Modified response was received
!
status
&&
s
.
isLocal
?
// yet no conditional request headers was provided
(
responses
.
text
?
200
:
404
)
:
}
else
if
(
status
===
304
&&
// IE - #1450: sometimes returns 1223 when it should be 204
!
headers
[
"if-modified-since"
]
&&
(
status
===
1223
?
204
:
status
);
!
headers
[
"if-none-match"
]
)
{
status
=
200
;
// Status 0 encompasses several cases
}
else
if
(
!
status
)
{
// Cross-domain
if
(
s
.
crossDomain
)
{
if
(
!
s
.
statusText
)
{
// FF, Webkit (other?): There is no status text for errors
// 302 is the most generic cross-domain status code
// for errors, could be anything really (even a real 0)
status
=
302
;
}
// All same-domain: for local files, 0 is a success
}
else
if
(
s
.
isLocal
)
{
status
=
200
;
// Opera: this notifies success for all requests
// (verified in 11.01). Patch welcome.
}
// Opera - #6060: sets status as 0 for 304
// Patch welcome.
}
}
}
}
}
}
catch
(
firefoxAccessException
)
{
}
catch
(
firefoxAccessException
)
{
...
...
test/localfile.html
View file @
3a1d7a3c
...
@@ -27,20 +27,25 @@
...
@@ -27,20 +27,25 @@
.success
{
color
:
green
;
}
.success
{
color
:
green
;
}
</style>
</style>
</head>
</head>
<body>
<body>
<h1>
jQuery Local File Test
</h1>
<h1>
jQuery Local File Test
</h1>
<h2>
Introduction
</h2>
<ul>
<ul>
<li>
<li>
Access this file using the "file:" protocol,
Access this file using the "file:" protocol,
</li>
</li>
<li>
<li>
two "OK" strings must appear below,
two
green
"OK" strings must appear below,
</li>
</li>
<li>
<li>
Opera will fail at detecting errors, it's a known issue
.
Empty local files will issue errors, it's a known limitation
.
</li>
</li>
</ul>
</ul>
<h2>
Results
</h2>
<ul>
<ul>
<li>
<li>
Success:
Success:
...
@@ -53,26 +58,35 @@
...
@@ -53,26 +58,35 @@
</span>
</span>
</li>
</li>
</ul>
</ul>
<h2>
Logs:
</h2>
<ul
id=
"log"
>
</ul>
<script>
<script>
var
logUL
=
jQuery
(
"#log"
);
function
doLog
(
message
,
args
)
{
jQuery
(
"<li />"
).
appendTo
(
logUL
).
text
(
message
+
': "'
+
Array
.
prototype
.
join
.
call
(
args
,
'" - "'
)
+
'"'
);
}
jQuery
.
ajax
(
"./data/badjson.js"
,
{
jQuery
.
ajax
(
"./data/badjson.js"
,
{
context
:
jQuery
(
"#success"
),
context
:
jQuery
(
"#success"
),
dataType
:
"text"
dataType
:
"text"
}).
success
(
function
()
{
}).
success
(
function
(
data
,
_
,
xhr
)
{
console
&&
console
.
log
&&
console
.
log
(
"success/success
"
,
arguments
);
doLog
(
"Success ("
+
xhr
.
status
+
")
"
,
arguments
);
this
.
addClass
(
"success"
).
text
(
"OK"
);
this
.
addClass
(
data
?
"success"
:
"error"
).
text
(
"OK"
);
}).
error
(
function
()
{
}).
error
(
function
(
xhr
)
{
console
&&
console
.
log
&&
console
.
log
(
"success/error
"
,
arguments
);
doLog
(
"Success ("
+
xhr
.
status
+
")
"
,
arguments
);
this
.
addClass
(
"error"
).
text
(
"FAIL"
);
this
.
addClass
(
"error"
).
text
(
"FAIL"
);
});
});
jQuery
.
ajax
(
"./data/doesnotexist.ext"
,
{
jQuery
.
ajax
(
"./data/doesnotexist.ext"
,
{
context
:
jQuery
(
"#error"
),
context
:
jQuery
(
"#error"
),
dataType
:
"text"
dataType
:
"text"
}).
error
(
function
()
{
}).
error
(
function
(
xhr
)
{
console
&&
console
.
log
&&
console
.
log
(
"error/error
"
,
arguments
);
doLog
(
"Error ("
+
xhr
.
status
+
")
"
,
arguments
);
this
.
addClass
(
"success"
).
text
(
"OK"
);
this
.
addClass
(
"success"
).
text
(
"OK"
);
}).
success
(
function
()
{
}).
success
(
function
(
data
,
_
,
xhr
)
{
console
&&
console
.
log
&&
console
.
log
(
"error/success
"
,
arguments
);
doLog
(
"Error ("
+
xhr
.
status
+
")
"
,
arguments
);
this
.
addClass
(
$
.
browser
.
opera
?
"success"
:
"error"
).
text
(
"FAIL"
);
this
.
addClass
(
"error"
).
text
(
"FAIL"
);
});
});
</script>
</script>
</body>
</body>
\ No newline at end of file
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