Wednesday, 7 August 2013

How to send array values in a $.get call via jquery?

How to send array values in a $.get call via jquery?

Let's say I have multiple text boxes with array names, like:
<input type='text' name='test[]' class='test_tb' id='test1' value=''/>
<input type='text' name='test[]' class='test_tb' id='test2' value=''/>
Now if I was using a form, I could easily serialize it and send it, but I
want to know how to build it manually. I tried something like
$.get('test.php',{
'test[]':$("#test1").val(),
'test[]':$("#test2").val()
},function(d){
console.log(d);
});
But since a object can't have repeating keys, obviously this didn't
work...so what is the manual way of doing this?
PS: This is for learning purpose not any actual task.

No comments:

Post a Comment