jquery ajax post multi dimensional array to php -


i having download csv button exporting results csv. till using server side code this. sending selected dropdowns ids csvdownload.php page writing results in excel.

but now, want utility selecting search results using checkbox , selected results should written csv.

i planning table data in array , post php using ajax, rest of things. how possible post multiple rows of data php. i have following piece of code getting table data alerting data dont know how make array , pass php

      $('#tblsearchresults tr').filter(':has(:checkbox:checked)').each(function() {      $tr = $(this);        //alert($tr.find("td").eq(4).html());          var risk_cat = $tr.find("td").eq(1).html();         var risk_type = $tr.find("td").eq(2).html();         var risk_desc = $tr.find("td").eq(3).html();         var treat_desc = $tr.find("td").eq(4).html();         var treat_cat = $tr.find("td").eq(5).html();          selecteddata.push({"risk_cat": risk_cat, "risk_type": risk_type, "risk_desc": risk_desc, "treat_desc": treat_desc, "treat_cat": treat_cat}); 

thanks

i think need use json.stringify(selecteddata) in order use on serverside.

jquery:

var obj = { 'risk_cat': risk_cat, 'risk_type': risk_type }; selecteddata.push(obj);  $.post('serive.php', { dto: json.stringify(selecteddata) },  function(data){ /* handle response,  */ }); 

service.php:

header('content-type: application/json'); header('cache-control: no-cache, must-revalidate');  $foo = json_decode($_post['dto']);   $arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5); //example data  echo json_encode($arr); 

this should started. in ajax reponse, alert(data.a) alerting "1"


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -