Created
December 9, 2011 00:48
-
-
Save avk/1449532 to your computer and use it in GitHub Desktop.
Titanium Mobile properly serializing JSON into a query string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url = "http://localhost:3000"; | |
var params = { | |
foo: 'bar', | |
stuff: [1,2,3] | |
}; | |
var xhr = Ti.Network.createHTTPClient({ | |
onload: function() { | |
alert("load!"); | |
}, | |
onerror: function() { | |
alert("error!"); | |
} | |
}); | |
xhr.open('POST', url); | |
xhr.setRequestHeader("Content-Type","application/json"); | |
params = JSON.stringify(params); | |
xhr.send(params); | |
// parameters from Rails log: | |
// Parameters: {"stuff"=>[1, 2, 3], "action"=>"index", "foo"=>"bar", "controller"=>"home"} | |
// NOTE: | |
// parameters will be garbled without the application/json Content-Type | |
// parameters will also be garbled without JSON.stringify, even though the Titanium docs say that xhr.send() should do this automatically |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment