Fixed #2046 by forcing the dataType to 'html' in the .load() function.

This commit is contained in:
David Serduke 2007-12-14 17:06:41 +00:00
parent 56a93fc2cc
commit 06c2f06a21
2 changed files with 24 additions and 10 deletions

View file

@ -34,6 +34,7 @@ jQuery.fn.extend({
jQuery.ajax({ jQuery.ajax({
url: url, url: url,
type: type, type: type,
dataType: "html",
data: params, data: params,
complete: function(res, status){ complete: function(res, status){
// If successful, inject the HTML into all the matched elements // If successful, inject the HTML into all the matched elements

View file

@ -317,6 +317,19 @@ test("load('url selector')", function() {
}); });
}); });
test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
expect(1);
stop();
$.ajaxSetup({ dataType: "json" });
$("#first").ajaxComplete(function (e, xml, s) {
equals( s.dataType, "html", "Verify the load() dataType was html" );
$("#first").unbind("ajaxComplete");
$.ajaxSetup({ dataType: "" });
start();
});
$('#first').load("data/test3.html");
});
test("load(String, Function) - simple: inject text into DOM", function() { test("load(String, Function) - simple: inject text into DOM", function() {
expect(2); expect(2);
stop(); stop();
@ -332,15 +345,15 @@ test("load(String, Function) - check scripts", function() {
window.testFoo = undefined; window.testFoo = undefined;
window.foobar = null; window.foobar = null;
var verifyEvaluation = function() { var verifyEvaluation = function() {
equals( foobar, "bar", 'Check if script src was evaluated after load' ); equals( foobar, "bar", 'Check if script src was evaluated after load' );
equals( $('#ap').html(), 'bar', 'Check if script evaluation has modified DOM'); equals( $('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
start(); start();
}; };
$('#first').load(url('data/test.html'), function() { $('#first').load(url('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' );
equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
equals( testFoo, "foo", 'Check if script was evaluated after load' ); equals( testFoo, "foo", 'Check if script was evaluated after load' );
setTimeout(verifyEvaluation, 600); setTimeout(verifyEvaluation, 600);
}); });
}); });
@ -349,9 +362,9 @@ test("load(String, Function) - check file with only a script tag", function() {
stop(); stop();
testFoo = undefined; testFoo = undefined;
$('#first').load(url('data/test2.html'), function() { $('#first').load(url('data/test2.html'), function() {
ok( $('#foo').html() == 'foo', 'Check if script evaluation has modified DOM'); ok( $('#foo').html() == 'foo', 'Check if script evaluation has modified DOM');
ok( testFoo == "foo", 'Check if script was evaluated after load' ); ok( testFoo == "foo", 'Check if script was evaluated after load' );
start(); start();
}); });
}); });