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
ae58d24f
Commit
ae58d24f
authored
Nov 21, 2006
by
Jörn Zaefferer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Another attempt to fix the getScript problem
parent
953bf593
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
28 deletions
+22
-28
name.php
build/test/data/name.php
+1
-1
test.html
build/test/data/test.html
+2
-1
ajax.js
src/ajax/ajax.js
+10
-11
ajaxTest.js
src/ajax/ajaxTest.js
+9
-15
No files found.
build/test/data/name.php
View file @
ae58d24f
...
@@ -18,5 +18,5 @@ if($name == 'foo') {
...
@@ -18,5 +18,5 @@ if($name == 'foo') {
echo
"pan"
;
echo
"pan"
;
die
();
die
();
}
}
echo
"ERROR"
;
echo
'ERROR <script type="text/javascript">ok( true, "name.php executed" );</script>'
;
?>
?>
\ No newline at end of file
build/test/data/test.html
View file @
ae58d24f
html text
<br/>
html text
<br/>
<script
type=
"text/javascript"
>
/* <![CDATA[ */
<script
type=
"text/javascript"
>
/* <![CDATA[ */
foo
=
"foo"
;
$
(
'#foo'
).
html
(
'foo'
);
testFoo
=
"foo"
;
$
(
'#foo'
).
html
(
'foo'
);
ok
(
true
,
"test.html executed"
);
/* ]]> */
</script>
/* ]]> */
</script>
<script
src=
"data/test.js"
></script>
<script
src=
"data/test.js"
></script>
blabla
blabla
\ No newline at end of file
src/ajax/ajax.js
View file @
ae58d24f
...
@@ -124,12 +124,7 @@ jQuery.fn.extend({
...
@@ -124,12 +124,7 @@ jQuery.fn.extend({
// for some weird reason, it doesn't work if the callback is ommited
// for some weird reason, it doesn't work if the callback is ommited
jQuery
.
getScript
(
this
.
src
);
jQuery
.
getScript
(
this
.
src
);
else
{
else
{
// TODO extract into $.eval
jQuery
.
eval
(
this
.
text
||
this
.
textContent
||
this
.
innerHTML
||
""
);
var
data
=
this
.
text
||
this
.
textContent
||
this
.
innerHTML
||
""
;
if
(
window
.
execScript
)
window
.
execScript
(
data
);
else
window
.
setTimeout
(
data
,
0
);
}
}
}).
end
();
}).
end
();
}
}
...
@@ -688,12 +683,8 @@ jQuery.extend({
...
@@ -688,12 +683,8 @@ jQuery.extend({
data
=
type
==
"xml"
||
data
?
r
.
responseXML
:
r
.
responseText
;
data
=
type
==
"xml"
||
data
?
r
.
responseXML
:
r
.
responseText
;
// If the type is "script", eval it in global context
// If the type is "script", eval it in global context
// TODO extract as $.eval
if
(
type
==
"script"
)
{
if
(
type
==
"script"
)
{
if
(
window
.
execScript
)
jQuery
.
eval
(
data
);
window
.
execScript
(
data
);
else
window
.
setTimeout
(
data
,
0
);
}
}
// Get the JavaScript object, if JSON is used.
// Get the JavaScript object, if JSON is used.
...
@@ -734,6 +725,14 @@ jQuery.extend({
...
@@ -734,6 +725,14 @@ jQuery.extend({
// Return the resulting serialization
// Return the resulting serialization
return
s
.
join
(
"&"
);
return
s
.
join
(
"&"
);
},
// TODO document me
eval
:
function
(
data
)
{
if
(
window
.
execScript
)
window
.
execScript
(
data
);
else
eval
.
call
(
window
,
data
);
}
}
});
});
src/ajax/ajaxTest.js
View file @
ae58d24f
module
(
"ajax"
);
module
(
"ajax"
);
test
(
"load(String, Object, Function) - simple: inject text into DOM"
,
function
()
{
test
(
"load(String, Object, Function) - simple: inject text into DOM"
,
function
()
{
expect
(
1
);
expect
(
2
);
stop
();
stop
();
$
(
'#first'
).
load
(
"data/name.php"
,
function
()
{
$
(
'#first'
).
load
(
"data/name.php"
,
function
()
{
ok
(
$
(
'#first'
).
text
()
==
'ERROR'
,
'Check if content was injected into the DOM'
);
ok
(
/^ERROR/
.
test
(
$
(
'#first'
).
text
())
,
'Check if content was injected into the DOM'
);
start
();
start
();
});
});
});
});
...
@@ -13,17 +13,12 @@ test("load(String, Object, Function) - inject without callback", function() {
...
@@ -13,17 +13,12 @@ test("load(String, Object, Function) - inject without callback", function() {
expect
(
1
);
expect
(
1
);
stop
();
// check if load can be called with only url
stop
();
// check if load can be called with only url
$
(
'#first'
).
load
(
"data/name.php"
);
$
(
'#first'
).
load
(
"data/name.php"
);
$
.
get
(
"data/name.php"
,
function
()
{
ok
(
$
(
'#first'
).
text
()
==
'ERROR'
,
'Check if load works without callback'
);
start
();
});
});
});
test
(
"load(String, Object, Function) - check scripts"
,
function
()
{
test
(
"load(String, Object, Function) - check scripts"
,
function
()
{
expect
(
6
);
expect
(
7
);
stop
();
stop
();
window
.
foobar
=
undefined
;
testFoo
=
undefined
;
window
.
foo
=
undefined
;
var
verifyEvaluation
=
function
()
{
var
verifyEvaluation
=
function
()
{
ok
(
foobar
==
"bar"
,
'Check if script src was evaluated after load'
);
ok
(
foobar
==
"bar"
,
'Check if script src was evaluated after load'
);
ok
(
$
(
'#foo'
).
html
()
==
'foo'
,
'Check if script evaluation has modified DOM'
);
ok
(
$
(
'#foo'
).
html
()
==
'foo'
,
'Check if script evaluation has modified DOM'
);
...
@@ -32,7 +27,7 @@ test("load(String, Object, Function) - check scripts", function() {
...
@@ -32,7 +27,7 @@ test("load(String, Object, Function) - check scripts", function() {
};
};
$
(
'#first'
).
load
(
'data/test.html'
,
function
()
{
$
(
'#first'
).
load
(
'data/test.html'
,
function
()
{
ok
(
$
(
'#first'
).
html
().
match
(
/^html text/
),
'Check content after loading html'
);
ok
(
$
(
'#first'
).
html
().
match
(
/^html text/
),
'Check content after loading html'
);
ok
(
f
oo
==
"foo"
,
'Check if script was evaluated after load'
);
ok
(
testF
oo
==
"foo"
,
'Check if script was evaluated after load'
);
setTimeout
(
verifyEvaluation
,
600
);
setTimeout
(
verifyEvaluation
,
600
);
});
});
});
});
...
@@ -109,7 +104,7 @@ test("$.getIfModified(String, Hash, Function)", function() {
...
@@ -109,7 +104,7 @@ test("$.getIfModified(String, Hash, Function)", function() {
expect
(
1
);
expect
(
1
);
stop
();
stop
();
$
.
getIfModified
(
"data/name.php"
,
function
(
msg
)
{
$
.
getIfModified
(
"data/name.php"
,
function
(
msg
)
{
ok
(
msg
==
'ERROR'
,
'Check ifModified'
);
ok
(
/^ERROR/
.
test
(
msg
)
,
'Check ifModified'
);
start
();
start
();
});
});
});
});
...
@@ -238,10 +233,9 @@ test("$.ajax - simple post", function() {
...
@@ -238,10 +233,9 @@ test("$.ajax - simple post", function() {
});
});
test
(
"$.ajax - dataType html"
,
function
()
{
test
(
"$.ajax - dataType html"
,
function
()
{
expect
(
4
);
expect
(
5
);
stop
();
stop
();
window
.
foobar
=
undefined
;
testFoo
=
undefined
;
window
.
foo
=
undefined
;
var
verifyEvaluation
=
function
()
{
var
verifyEvaluation
=
function
()
{
ok
(
foobar
==
"bar"
,
'Check if script src was evaluated for datatype html'
);
ok
(
foobar
==
"bar"
,
'Check if script src was evaluated for datatype html'
);
start
();
start
();
...
@@ -251,7 +245,7 @@ test("$.ajax - dataType html", function() {
...
@@ -251,7 +245,7 @@ test("$.ajax - dataType html", function() {
url
:
"data/test.html"
,
url
:
"data/test.html"
,
success
:
function
(
data
)
{
success
:
function
(
data
)
{
ok
(
data
.
match
(
/^html text/
),
'Check content for datatype html'
);
ok
(
data
.
match
(
/^html text/
),
'Check content for datatype html'
);
ok
(
f
oo
==
"foo"
,
'Check if script was evaluated for datatype html'
);
ok
(
testF
oo
==
"foo"
,
'Check if script was evaluated for datatype html'
);
setTimeout
(
verifyEvaluation
,
600
);
setTimeout
(
verifyEvaluation
,
600
);
}
}
});
});
...
...
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