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
6861b5d4
Commit
6861b5d4
authored
Jan 06, 2010
by
jeresig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added in support for content-type sniffing for scripts. Fixes #5718.
parent
787f2710
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
6 deletions
+25
-6
ajax.js
src/ajax.js
+4
-6
script.php
test/data/script.php
+7
-0
ajax.js
test/unit/ajax.js
+14
-0
No files found.
src/ajax.js
View file @
6861b5d4
...
@@ -555,9 +555,8 @@ jQuery.extend({
...
@@ -555,9 +555,8 @@ jQuery.extend({
},
},
httpData
:
function
(
xhr
,
type
,
s
)
{
httpData
:
function
(
xhr
,
type
,
s
)
{
var
ct
=
xhr
.
getResponseHeader
(
"content-type"
),
var
ct
=
xhr
.
getResponseHeader
(
"content-type"
)
||
""
,
xml
=
type
===
"xml"
||
!
type
&&
ct
&&
ct
.
indexOf
(
"xml"
)
>=
0
,
xml
=
type
===
"xml"
||
!
type
&&
ct
.
indexOf
(
"xml"
)
>=
0
,
json
=
type
===
"json"
||
!
type
&&
ct
&&
ct
.
indexOf
(
"json"
)
>=
0
,
data
=
xml
?
xhr
.
responseXML
:
xhr
.
responseText
;
data
=
xml
?
xhr
.
responseXML
:
xhr
.
responseText
;
if
(
xml
&&
data
.
documentElement
.
nodeName
===
"parsererror"
)
{
if
(
xml
&&
data
.
documentElement
.
nodeName
===
"parsererror"
)
{
...
@@ -572,14 +571,13 @@ jQuery.extend({
...
@@ -572,14 +571,13 @@ jQuery.extend({
// The filter can actually parse the response
// The filter can actually parse the response
if
(
typeof
data
===
"string"
)
{
if
(
typeof
data
===
"string"
)
{
// If the type is "script", eval it in global context
// If the type is "script", eval it in global context
if
(
type
===
"script"
)
{
if
(
type
===
"script"
||
!
type
&&
ct
.
indexOf
(
"javascript"
)
>=
0
)
{
jQuery
.
globalEval
(
data
);
jQuery
.
globalEval
(
data
);
}
}
// Get the JavaScript object, if JSON is used.
// Get the JavaScript object, if JSON is used.
if
(
json
)
{
if
(
type
===
"json"
||
!
type
&&
ct
.
indexOf
(
"json"
)
>=
0
)
{
// Try to use the native JSON parser first
// Try to use the native JSON parser first
try
{
try
{
data
=
JSON
.
parse
(
data
);
data
=
JSON
.
parse
(
data
);
...
...
test/data/script.php
0 → 100644
View file @
6861b5d4
<?php
error_reporting
(
0
);
if
(
$_REQUEST
[
'header'
]
)
{
header
(
"Content-type: text/javascript"
);
}
?>
ok( true, "Script executed correctly." );
test/unit/ajax.js
View file @
6861b5d4
...
@@ -797,6 +797,20 @@ test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
...
@@ -797,6 +797,20 @@ test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
});
});
});
});
test
(
"jQuery.ajax() - script by content-type"
,
function
()
{
expect
(
1
);
stop
();
jQuery
.
ajax
({
url
:
"data/script.php"
,
data
:
{
header
:
"script"
},
success
:
function
()
{
start
();
}
});
});
test
(
"jQuery.ajax() - json by content-type"
,
function
()
{
test
(
"jQuery.ajax() - json by content-type"
,
function
()
{
expect
(
5
);
expect
(
5
);
...
...
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