Hi there, I'm encountering some problems trying to submit an original html form array to a remote web server PHP page via xhr POST method.
As an example, I need to submit the following form:
<form method="post" action="http://www.mysite.com/"> <input name="option[123]" value="205"> <input name="option[124]" value="409"> <input name="otherparams" value="1"> ... </form>so the only way I found to manage this is the following code:
var client = Ti.Network.createHTTPClient({ onload : function(e) { Ti.API.info(this.responseText); }, onerror : function(e) { Ti.API.error(e.error); }, timeout : 100000 // in milliseconds }); client.open("POST", url); client.send({'otherparams': 1, 'option[123]': 205, 'option[124]': 409});where the PHP page (with a print_r($_REQUEST)) returns
Array ( [otherparams] => 1 [option] => Array ( [124] => 409 [123] => 205 ) )now the problem is, how can I dinamically build my object? As an example, any way I tryed to make something like
... var mynumber1 = '123', mynumber2 = '124'; client.send({'otherparams': 1, 'option['+mynumber+']': 205, 'option['+mynumber2+']': 409}); /* OR */ var myObj = {}; myObj.otherparams = 1; eval("myObj.option["+mynumber+"] = 205;"); client.send([myObj]);unfortunately failed...
Does anybody alredy realized how to do that? I absolutely cannot change the way my server manage requests parameters...
Thanks in advance to everybody...
Your Answer
Think you can help? Login to answer this question!