Permalink
Browse files

Merge branch 'master' of github.com:madrobby/zepto

  • Loading branch information...
2 parents 6909ee7 + efeedfc commit 4497f4f8a4a6858c177413b71d9bb4039069f5d4 @madrobby committed Mar 19, 2011
Showing with 33 additions and 0 deletions.
  1. +16 −0 src/ajax.js
  2. +17 −0 test/ajax.html
View
@@ -36,6 +36,22 @@
if (!settings.url) settings.url = window.location.toString();
if (settings.data && !settings.contentType) settings.contentType = "application/x-www-form-urlencoded";
+ if (settings.type.match(/get/i) && settings.data) {
+ var queryString,
+ objectType = Object.prototype.toString.call(settings.data).slice(8, -1);
+ if (objectType == 'Object' || objectType == 'Array') {
+ queryString = $.param(settings.data);
+ } else {
+ queryString = settings.data;
+ }
+ if (settings.url.match(/\?.*=/)) {
+ queryString = '&' + queryString;
+ } else if (queryString.slice(0, 1) !== '?') {
+ queryString = '?' + queryString;
+ }
+ settings.url = settings.url + queryString;
+ }
+
var mime = settings.accepts[settings.dataType],
xhr = new XMLHttpRequest();
View
@@ -201,6 +201,23 @@
t.assertEqual('hello=world&array[]=1&array[]=2&array[]=3&object[prop1]=val&object[prop2]=2', MockXHR.last.data);
},
+ testDataIsAppendedToGETURL: function(t) {
+ $.ajax({ url:'test.html', data:'foo=bar' });
+ t.assertEqual('test.html?foo=bar', MockXHR.last.url);
+
+ $.ajax({ url:'test.html', data:'?foo=bar' });
+ t.assertEqual('test.html?foo=bar', MockXHR.last.url);
+
+ $.ajax({ url:'test.html?bar=baz', data:'foo=bar' });
+ t.assertEqual('test.html?bar=baz&foo=bar', MockXHR.last.url);
+
+ $.ajax({ url:'test.html', data:{foo:'bar'} });
+ t.assertEqual('test.html?foo=bar', MockXHR.last.url);
+
+ $.ajax({ url:'test.html?bar=baz', data:'foo=bar' });
+ t.assertEqual('test.html?bar=baz&foo=bar', MockXHR.last.url);
+ },
+
testErrorCallback: function(t) {
var successFired = false, xhr, status;
$.ajax({

0 comments on commit 4497f4f

Please sign in to comment.