Bug Tracker

Ticket #5123: chrome-ajax-data.patch

File chrome-ajax-data.patch, 1.8 KB (added by mislav, 10 years ago)

Chrome patch

  • src/ajax.js

    From 27c4ea613648d9ca1759e8d3d8deb16c590ec1a2 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Mislav=20Marohni=C4=87?= <mislav.marohnic@gmail.com>
    Date: Tue, 30 Mar 2010 23:34:09 +0200
    Subject: [PATCH] ensure that `undefined` is never sent as Ajax data to xhr.send()
    
    This fixes Google Chrome making POST/PUT/DELETE requests with empty data.
    When `data` isn't specified by user, its value is (naturally) `undefined`
    which causes Chrome to actually send "undefined" in the HTTP request body.
    ---
     src/ajax.js            |    2 +-
     test/data/echoData.php |    1 +
     test/unit/ajax.js      |   13 +++++++++++++
     3 files changed, 15 insertions(+), 1 deletions(-)
     create mode 100644 test/data/echoData.php
    
    diff --git a/src/ajax.js b/src/ajax.js
    index 7cf280a..f4301f1 100644
    a b jQuery.extend({ 
    474474
    475475                // Send the data
    476476                try {
    477                         xhr.send( type === "POST" || type === "PUT" || type === "DELETE" ? s.data : null );
     477                        xhr.send( (type !== "GET" && s.data) || null );
    478478
    479479                } catch( sendError ) {
    480480                        jQuery.ajax.handleError( s, xhr, null, e );
  • new file test/data/echoData.php

    diff --git a/test/data/echoData.php b/test/data/echoData.php
    new file mode 100644
    index 0000000..5da01dc
    - +  
     1<?php echo file_get_contents('php://input'); ?>
     2 No newline at end of file
  • test/unit/ajax.js

    diff --git a/test/unit/ajax.js b/test/unit/ajax.js
    index be4b3f0..58aa615 100644
    a b test("data option: evaluate function values (#2806)", function() { 
    11631163        })
    11641164});
    11651165
     1166test("data option: empty bodies for non-GET requests", function() {
     1167        stop();
     1168        jQuery.ajax({
     1169                url: "data/echoData.php",
     1170                data: undefined,
     1171                type: "post",
     1172                success: function(result) {
     1173                        equals( result, "" );
     1174                        start();
     1175                }
     1176        })
     1177});
     1178
    11661179test("jQuery.ajax - If-Modified-Since support", function() {
    11671180        expect( 3 );
    11681181