jquery - javascript new Array -> php array -
i have page has bunch of tick boxes, these identified name="a number". when button clicked, have javascript function creates new array numbers of boxes ticked. gets sent page 'test.php'.
it returns:
array ( [data] => [null,"47284","47282","47281","47280","47279","47278","47277","47276","47269"] ) when try , explode array array string conversion error.
what doing wrong?
i need these numbers separated can sql query each.
javascript code:
<script> var selected = new array(); function showmessage() { var selected = array(); $('input:checked').each(function() { selected.push($(this).attr('name')); }); var answer = confirm('are sure want send these emails again?'); if(answer) { var jsonstring = json.stringify(selected); $.ajax({ url: "../../test.php", type: "post", data: {data : jsonstring}, success: function(data){ alert(data); } }) } } </script> <script language="javascript"> $(function(){ // add multiple select / deselect functionality $("#selectallsent").click(function () { $('.yes').prop('checked', this.checked); }); $("#selectallprogress").click(function () { $('.no').prop('checked', this.checked); }); // if checkbox selected, check selectall checkbox // , viceversa $(".yes").click(function(){ if($(".yes").length == $(".yes:checked").length) { $("#selectallsent").prop("checked", "checked"); } else { $("#selectallsent").removeattr("checked"); } }); $(".no").click(function(){ if($(".no").length == $(".no:checked").length) { $("#selectallprogress").prop("checked", "checked"); } else { $("#selectallprogress").removeattr("checked"); } }); }); </script> test.php code:
<? print_r($_post); ?> i know need more on test.php page know is.
two things need ....
first 1 not stringify selected object (jquery deal you)
function showmessage() { var selected = array(); $('input:checked').each(function() { selected.push($(this).attr('name')); }); var answer = confirm('are sure want send these emails again?'); if(answer) { $.ajax({ url: "../../test.php", type: "post", data: {data : selected}, success: function(data){ alert(data); } }) } } then on php side can access values via
print_r($_post["data"]); this array of inputs.
Comments
Post a Comment