Send array in JS to php
I'm trying to do something similar to this question. I want to send to the server the id's of the selected checkboxes. I'm using jquery only because the example. my ajax code is pure JS.开发者_JAVA百科
This is my code:
js:
function DeleteTest(ind)
{
if (confirm('Are you sure you want to delete this test?'))
{
$(function() {
var testdel = $('input[name=deletetest]').serialize();
alert(testdel);
window.open('test.php' + "?"+testdel,'_self');
} );
return true;}
else { return false;}
}
oCell.innerHTML = "<input type='checkbox' name='deletetest' value='"+ ind + "')';>"; // create checkbox for each row in ajax
html:
<form id="checkboxform" action="test.php" method="post">
<tbody id="auditTblBody">
</tbody>
</table>
<input type="button" value="Submit AJAX Request" onclick="DeleteTest()" />
</form>
With this code i get only one value with GET.testdel
is fine. (i.e deletetest=477&deletetest=476
) my problem is how to send this information.
thank you!
For PHP to recognize multiple values from inputs with the same name, that name must end in the characters []
.
oCell.innerHTML = "<input type='checkbox' name='deletetest[]' value='"+ ind + "')';>";
O/p: deletetest=477&deletetest=476
send the o/p in json format to a particular php file from javascript & you can decode it in redirected php file using json_decode
精彩评论