Skip to content

Commit

Permalink
Fixed #1750 by adding a url that starts with "//" and is a dataType "…
Browse files Browse the repository at this point in the history
…script" will now use a cross domain load the same as urls that start with "http".
  • Loading branch information
davids549 committed Dec 12, 2007
1 parent 58c640f commit e1af5fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ajax.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ jQuery.extend({


// If we're requesting a remote document // If we're requesting a remote document
// and trying to load JSON or Script with a GET // and trying to load JSON or Script with a GET
if ( !s.url.indexOf("http") && ( s.dataType == "script" || s.dataType =="json" ) && s.type.toLowerCase() == "get" ) { if ( (!s.url.indexOf("http") || !s.url.indexOf("//")) && ( s.dataType == "script" || s.dataType =="json" ) && s.type.toLowerCase() == "get" ) {
var head = document.getElementsByTagName("head")[0]; var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script"); var script = document.createElement("script");
script.src = s.url; script.src = s.url;
Expand Down
22 changes: 22 additions & 0 deletions test/unit/ajax.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ test("$.get(String, Hash, Function) - parse xml and use text() on nodes", functi
test("$.getScript(String, Function) - with callback", function() { test("$.getScript(String, Function) - with callback", function() {
expect(2); expect(2);
stop(); stop();
window.foobar = null;
$.getScript(url("data/test.js"), function() { $.getScript(url("data/test.js"), function() {
equals( foobar, "bar", 'Check if script was evaluated' ); equals( foobar, "bar", 'Check if script was evaluated' );
setTimeout(start, 100); setTimeout(start, 100);
Expand Down Expand Up @@ -563,6 +564,7 @@ test("$.ajax() - script, Remote", function() {


stop(); stop();


window.foobar = null;
$.ajax({ $.ajax({
url: base + "data/test.js", url: base + "data/test.js",
dataType: "script", dataType: "script",
Expand All @@ -580,6 +582,7 @@ test("$.ajax() - script, Remote with POST", function() {


stop(); stop();


window.foobar = null;
$.ajax({ $.ajax({
url: base + "data/test.js", url: base + "data/test.js",
type: "POST", type: "POST",
Expand All @@ -592,6 +595,25 @@ test("$.ajax() - script, Remote with POST", function() {
}); });
}); });


test("$.ajax() - script, Remote with scheme-less URL", function() {
expect(2);

var base = window.location.href.replace(/\?.*$/, "");
base = base.replace(/^.*?\/\//, "//");

stop();

window.foobar = null;
$.ajax({
url: base + "data/test.js",
dataType: "script",
success: function(data){
ok( foobar, "Script results returned (GET, no callback)" );
start();
}
});
});

test("$.getJSON(String, Hash, Function) - JSON array", function() { test("$.getJSON(String, Hash, Function) - JSON array", function() {
expect(4); expect(4);
stop(); stop();
Expand Down

0 comments on commit e1af5fa

Please sign in to comment.