From b292c4c2df673d17d8c720e13d4d81ecae4ec499 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Thu, 16 Aug 2012 16:45:18 +0200 Subject: [PATCH] Calling load with null as the data parameter now properly issues a GET request, not a POST request. Unit tests added. Fixes #12234. --- src/ajax.js | 2 +- test/unit/ajax.js | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index f3887ff44..cfbfcd527 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -170,7 +170,7 @@ jQuery.fn.load = function( url, params, callback ) { params = undefined; // Otherwise, build a param string - } else if ( typeof params === "object" ) { + } else if ( params && typeof params === "object" ) { type = "POST"; } diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 2371f8982..1345eae3a 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1037,11 +1037,45 @@ test("global ajaxSettings", function() { */ test("load(String)", function() { - expect(1); + expect(2); stop(); // check if load can be called with only url + jQuery.ajaxSetup({ + beforeSend: function() { + strictEqual( this.type, "GET", "no data means GET request" ); + } + }); jQuery("#first").load("data/name.html", function() { start(); }); + jQuery.ajaxSetup({ + beforeSend: null + }); +}); + +test("load(String,null)", function() { + expect(2); + stop(); // check if load can be called with url and null data + jQuery.ajaxSetup({ + beforeSend: function() { + strictEqual( this.type, "GET", "no data means GET request" ); + } + }); + jQuery("#first").load("data/name.html", null, function() { + start(); + }); +}); + +test("load(String,undefined)", function() { + expect(2); + stop(); // check if load can be called with url and null data + jQuery.ajaxSetup({ + beforeSend: function() { + strictEqual( this.type, "GET", "no data means GET request" ); + } + }); + jQuery("#first").load("data/name.html", undefined, function() { + start(); + }); }); test("load('url selector')", function() { -- 2.39.5