Skip to content

Commit

Permalink
respect traditional: true option in $.ajax()
Browse files Browse the repository at this point in the history
Forward the value of `traditional` option to $.param() in order to
activate flat parameter serialization for certain backends such as
Django.

Closes madrobby#484
  • Loading branch information
Gabriel Reitz Giannattasio authored and mislav committed Sep 27, 2012
1 parent e92dc43 commit ec030b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@

// serialize payload and append it to the URL for GET requests
function serializeData(options) {
if (isObject(options.data)) options.data = $.param(options.data)
if (isObject(options.data)) options.data = $.param(options.data, options.traditional)
if (options.data && (!options.type || options.type.toUpperCase() == 'GET'))
options.url = appendQuery(options.url, options.data)
}
Expand Down
6 changes: 6 additions & 0 deletions test/ajax.html
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ <h1>Zepto Ajax unit tests</h1>
t.assertEqual('hello=world&array[]=1&array[]=2&array[]=3&object[prop1]=val&object[prop2]=2', MockXHR.last.data)
},

testDataOptionIsConvertedToSerializedTraditionalForm: function(t) {
$.ajax({ data: {hello: 'world', array: [1,2,3], object: { prop1: 'val', prop2: 2 } }, traditional: true })
MockXHR.last.data = decodeURIComponent(MockXHR.last.data)
t.assertEqual('hello=world&array=1&array=2&array=3&object=[object+Object]', MockXHR.last.data)
},

testDataIsAppendedToGETURL: function(t) {
$.ajax({ url:'test.html', data:'foo=bar' })
t.assertEqual('test.html?foo=bar', MockXHR.last.url)
Expand Down

0 comments on commit ec030b3

Please sign in to comment.