aboutsummaryrefslogtreecommitdiffstats
path: root/src/ajax
diff options
context:
space:
mode:
authorJörn Zaefferer <joern.zaefferer@gmail.com>2006-11-21 09:55:34 +0000
committerJörn Zaefferer <joern.zaefferer@gmail.com>2006-11-21 09:55:34 +0000
commitae58d24fd55e33b9977516988e696466fdaefa18 (patch)
tree6e18635e43e257b720e6dbc11b4f0c012b63fd9a /src/ajax
parent953bf593a6233d9f480ee3f706d21950590f40ef (diff)
downloadjquery-ae58d24fd55e33b9977516988e696466fdaefa18.tar.gz
jquery-ae58d24fd55e33b9977516988e696466fdaefa18.zip
Another attempt to fix the getScript problem
Diffstat (limited to 'src/ajax')
-rw-r--r--src/ajax/ajax.js21
-rw-r--r--src/ajax/ajaxTest.js24
2 files changed, 19 insertions, 26 deletions
diff --git a/src/ajax/ajax.js b/src/ajax/ajax.js
index 652bd2d71..f0f448aa1 100644
--- a/src/ajax/ajax.js
+++ b/src/ajax/ajax.js
@@ -124,12 +124,7 @@ jQuery.fn.extend({
// for some weird reason, it doesn't work if the callback is ommited
jQuery.getScript( this.src );
else {
- // TODO extract into $.eval
- var data = this.text || this.textContent || this.innerHTML || "";
- if (window.execScript)
- window.execScript( data );
- else
- window.setTimeout( data, 0 );
+ jQuery.eval ( this.text || this.textContent || this.innerHTML || "" );
}
}).end();
}
@@ -688,12 +683,8 @@ jQuery.extend({
data = type == "xml" || data ? r.responseXML : r.responseText;
// If the type is "script", eval it in global context
- // TODO extract as $.eval
if ( type == "script" ) {
- if (window.execScript)
- window.execScript( data );
- else
- window.setTimeout( data, 0 );
+ jQuery.eval( data );
}
// Get the JavaScript object, if JSON is used.
@@ -734,6 +725,14 @@ jQuery.extend({
// Return the resulting serialization
return s.join("&");
+ },
+
+ // TODO document me
+ eval: function(data) {
+ if (window.execScript)
+ window.execScript( data );
+ else
+ eval.call( window, data );
}
});
diff --git a/src/ajax/ajaxTest.js b/src/ajax/ajaxTest.js
index ba5d4a46d..8123ae87f 100644
--- a/src/ajax/ajaxTest.js
+++ b/src/ajax/ajaxTest.js
@@ -1,10 +1,10 @@
module("ajax");
test("load(String, Object, Function) - simple: inject text into DOM", function() {
- expect(1);
+ expect(2);
stop();
$('#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();
});
});
@@ -13,17 +13,12 @@ test("load(String, Object, Function) - inject without callback", function() {
expect(1);
stop(); // check if load can be called with only url
$('#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() {
- expect(6);
+ expect(7);
stop();
- window.foobar = undefined;
- window.foo = undefined;
+ testFoo = undefined;
var verifyEvaluation = function() {
ok( foobar == "bar", 'Check if script src was evaluated after load' );
ok( $('#foo').html() == 'foo', 'Check if script evaluation has modified DOM');
@@ -32,7 +27,7 @@ test("load(String, Object, Function) - check scripts", function() {
};
$('#first').load('data/test.html', function() {
ok( $('#first').html().match(/^html text/), 'Check content after loading html' );
- ok( foo == "foo", 'Check if script was evaluated after load' );
+ ok( testFoo == "foo", 'Check if script was evaluated after load' );
setTimeout(verifyEvaluation, 600);
});
});
@@ -109,7 +104,7 @@ test("$.getIfModified(String, Hash, Function)", function() {
expect(1);
stop();
$.getIfModified("data/name.php", function(msg) {
- ok( msg == 'ERROR', 'Check ifModified' );
+ ok( /^ERROR/.test(msg), 'Check ifModified' );
start();
});
});
@@ -238,10 +233,9 @@ test("$.ajax - simple post", function() {
});
test("$.ajax - dataType html", function() {
- expect(4);
+ expect(5);
stop();
- window.foobar = undefined;
- window.foo = undefined;
+ testFoo = undefined;
var verifyEvaluation = function() {
ok( foobar == "bar", 'Check if script src was evaluated for datatype html' );
start();
@@ -251,7 +245,7 @@ test("$.ajax - dataType html", function() {
url: "data/test.html",
success: function(data) {
ok( data.match(/^html text/), 'Check content for datatype html' );
- ok( foo == "foo", 'Check if script was evaluated for datatype html' );
+ ok( testFoo == "foo", 'Check if script was evaluated for datatype html' );
setTimeout(verifyEvaluation, 600);
}
});