Skip to content

Commit

Permalink
support "processData" option for $.ajax()
Browse files Browse the repository at this point in the history
The "processData" option determines whether data should automatically be
serialized to string. Defaults to true.

Closes madrobby#595
  • Loading branch information
mnmly authored and mislav committed Sep 28, 2012
1 parent a2d8ea3 commit 189d946
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@
// Whether the request is to another domain
crossDomain: false,
// Default timeout
timeout: 0
timeout: 0,
// Whether data should be serialized to string
processData: true
}

function mimeToDataType(mime) {
Expand All @@ -152,7 +154,8 @@

// serialize payload and append it to the URL for GET requests
function serializeData(options) {
if (isObject(options.data)) options.data = $.param(options.data, options.traditional)
if (options.processData && 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
11 changes: 10 additions & 1 deletion test/ajax.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ <h1>Zepto Ajax unit tests</h1>
}
})
}

})

var OriginalXHR = $.ajaxSettings.xhr
Expand Down Expand Up @@ -413,6 +412,16 @@ <h1>Zepto Ajax unit tests</h1>
t.assertEqual('hello=world&array=1&array=2&array=3&object=[object+Object]', MockXHR.last.data)
},

testProcessDataDisabled: function(t) {
var data = { country: 'Ecuador' }
$.ajax({
data: data,
processData: false,
type: "POST"
})
t.assertIdentical(data, 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 189d946

Please sign in to comment.