]> source.dussan.org Git - jquery.git/commitdiff
Make sure that #... are trimmed from Ajax request URLs. Fixes #4987.
authorJohn Resig <jeresig@gmail.com>
Wed, 22 Sep 2010 16:52:44 +0000 (12:52 -0400)
committerJohn Resig <jeresig@gmail.com>
Wed, 22 Sep 2010 16:52:44 +0000 (12:52 -0400)
src/ajax.js
test/unit/ajax.js

index cc871330df16fbbc0216182f11f2ed8ee3ec974e..97d40391d905f0a6e3ad46ee84681617658c9d2e 100644 (file)
@@ -10,6 +10,7 @@ var jsc = jQuery.now(),
        rts = /([?&])_=[^&]*(&?)/,
        rurl = /^(\w+:)?\/\/([^\/?#]+)/,
        r20 = /%20/g,
+       rhash = /#[^#]*$/,
 
        // Keep a copy of the old load method
        _load = jQuery.fn.load;
@@ -205,6 +206,7 @@ jQuery.extend({
                var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings),
                        jsonp, status, data, type = s.type.toUpperCase();
 
+               s.url = s.url.replace( rhash, "" );
                s.context = origSettings && origSettings.context || s;
 
                // convert data if not already a string
index 7f3f39aff46c370ceed5e25c47f940fce8b83bdb..b7eb57d8e841ea458beb41069cff70fe2863e51f 100644 (file)
@@ -68,6 +68,35 @@ test("jQuery.ajax() - error callbacks", function() {
        });
 });
 
+test(".ajax() - hash", function() {
+       expect(3);
+
+       jQuery.ajax({
+               url: "data/name.html#foo",
+               beforeSend: function( xhr, settings ) {
+                       equals(settings.url, "data/name.html", "Make sure that the URL is trimmed.");
+                       return false;
+               }
+       });
+
+       jQuery.ajax({
+               url: "data/name.html?abc#foo",
+               beforeSend: function( xhr, settings ) {
+                       equals(settings.url, "data/name.html?abc", "Make sure that the URL is trimmed.");
+                       return false;
+               }
+       });
+
+       jQuery.ajax({
+               url: "data/name.html?abc#foo",
+               data: { "test": 123 },
+               beforeSend: function( xhr, settings ) {
+                       equals(settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed.");
+                       return false;
+               }
+       });
+});
+
 test(".ajax() - 304", function() {
        expect( 1 );
        stop();