Bug Tracker

Changeset 3295

Show
Ignore:
Timestamp:
09/15/07 01:18:30 (1 year ago)
Author:
jeresig
Message:

Added a fix for bug #1580, where the query string was appended to the POST data, instead of being left alone.

Location:
trunk/jquery
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/ajax.js

    r3294 r3295  
    164164            s.data = jQuery.param(s.data); 
    165165 
    166         // Break the data into one single string 
    167         var q = s.url.indexOf("?"); 
    168         if ( q > -1 ) { 
    169             s.data = (s.data ? s.data + "&" : "") + s.url.slice(q + 1); 
    170             s.url = s.url.slice(0, q); 
    171         } 
    172  
    173166        // Handle JSONP Parameter Callbacks 
    174167        if ( s.dataType == "jsonp" ) { 
    175             if ( !s.data || !s.data.match(jsre) ) 
     168            if ( s.type.toLowerCase() == "get" ) { 
     169                if ( !s.url.match(jsre) ) 
     170                    s.url += (s.url.match(/\?/) ? "&" : "?") + (s.jsonp || "callback") + "=?"; 
     171            } else if ( !s.data || !s.data.match(jsre) ) 
    176172                s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?"; 
    177173            s.dataType = "json"; 
     
    179175 
    180176        // Build temporary JSONP function 
    181         if ( s.dataType == "json" && s.data && s.data.match(jsre) ) { 
     177        if ( s.dataType == "json" && (s.data && s.data.match(jsre) || s.url.match(jsre)) ) { 
    182178            jsonp = "jsonp" + jsc++; 
    183             s.data = s.data.replace(jsre, "=" + jsonp); 
     179 
     180            // Replace the =? sequence both in the query string and the data 
     181            if ( s.data ) 
     182                s.data = s.data.replace(jsre, "=" + jsonp); 
     183            s.url = s.url.replace(jsre, "=" + jsonp); 
    184184 
    185185            // We need to make sure 
     
    202202 
    203203        if ( s.cache === false && s.type.toLowerCase() == "get" ) 
    204             s.data = (s.data ? s.data + "&" : "") + "_=" + (new Date()).getTime(); 
     204            s.url += (s.url.match(/\?/) ? "&" : "?") + "_=" + (new Date()).getTime(); 
    205205 
    206206        // If data is available, append data to url for get requests 
    207207        if ( s.data && s.type.toLowerCase() == "get" ) { 
    208             s.url += "?" + s.data; 
     208            s.url += (s.url.match(/\?/) ? "&" : "?") + s.data; 
    209209 
    210210            // IE likes to send both get and post data, prevent this 
  • trunk/jquery/test/unit/ajax.js

    r3293 r3295  
    517517 
    518518test("$.post(String, Hash, Function) - simple with xml", function() { 
    519     expect(2); 
     519    expect(4); 
    520520    stop(); 
    521521    $.post(url("data/name.php"), {xml: "5-2"}, function(xml){ 
     522      $('math', xml).each(function() { 
     523            ok( $('calculation', this).text() == '5-2', 'Check for XML' ); 
     524            ok( $('result', this).text() == '3', 'Check for XML' ); 
     525         }); 
     526    }); 
     527 
     528    $.post(url("data/name.php?xml=5-2"), {}, function(xml){ 
    522529      $('math', xml).each(function() { 
    523530            ok( $('calculation', this).text() == '5-2', 'Check for XML' );