BrettCarr Posted March 11, 2010 Share Posted March 11, 2010 Ok I can create this in one function This is the function that make the json_ string, if you un comment the last three lines you can see this work.Fistr the array <?php public function getArrayData() { $batchdate1 = date('Y-m-d', strtotime(preg_replace('/\//','-',$_POST['batch_date']))); if (isset($_POST['batch_number'])) { $_SESSION['batcharray'][] = array( "batch_date" => $batchdate1, "batch_number" => $_POST['batch_number'], "original_proof_num" => $_POST['original_proof_num'], "batch_status" => $_POST['batch_status'], "invoice_num_ccaus" => $_POST['invoice_num_ccaus'], "carrier" => $_POST['carrier'], "num_of_boxes" => $_POST['num_of_boxes'], "toll_consign_num" => $_POST['toll_consign_num'], "custId" => $_POST['custId'], "venueId" => $_POST['venueId'], "bpay" => $_POST['bpay'], "proof_tracking_comments" => $_POST['proof_tracking_comments'], "veunue_comments" => $_POST['veunue_comments'], ); } } ?> Now the function tha makes the string <?php public function myJsonString() { $test = json_encode($_SESSION['batcharray']); $str = "(". $test .")" ; var_dump($str); eval("\$str = \"$str\";"); var_dump($str); $str = substr($str, 1, strlen($str) - 2); // remove outer ( and ) $str = preg_replace("/([a-zA-Z0-9_]+?):/" , "\"$1\":", $str); // fix variable names echo "<br/>"; echo "Ok string is created" ."<br/>"; $_SESSION['myJsonString'] = $str; //var_dump($str); //$output = json_decode($str, true); //var_dump($output); }?> Finallay the ajax send <script language="javascript" type="text/javascript" src="/scripts/network.js"></script> <script language="javascript" type="text/javascript"> function addDatadb() { myarray = <?= $_SESSION['myJsonString'] ?>; send( '/ajax/arrayclean.php', 'myarray=' + myarray, null , null); alert(myarray); } this is on the server side <?php $str = $_REQUEST['myJsonString']; var_dump($str); $output = json_decode($str, true); var_dump($output); foreach ($output as $ojb) { $comma_separated = implode("','", $ojb); $myquery = "INSERT INTO batch_import VALUES(null,'$comma_separated','0');"; echo $myquery . "<br />"; $db->query($myquery); } ?> Im so very very lost as to why this won't work Please help Im new PHP AND to this forum I hope this post is correct ANY HELP OR ADVICE IS VERY WELCOME AND NEEDED Quote Link to comment https://forums.phpfreaks.com/topic/194858-json-str-through-ajax-please-help/ Share on other sites More sharing options...
Alex Posted March 11, 2010 Share Posted March 11, 2010 You need to be more specific. How isn't it working, are you getting some kind of an error, unexpected results (if so, what are they), or what? Quote Link to comment https://forums.phpfreaks.com/topic/194858-json-str-through-ajax-please-help/#findComment-1024584 Share on other sites More sharing options...
BrettCarr Posted March 11, 2010 Author Share Posted March 11, 2010 THIS IS THE STRING THAT MY FUNCTION MAKES"[{"batch_date":"1970-01-01","batch_number":"","original_proof_num":"596","batch_status":"New","invoice_num_ccaus":"","carrier":"Toll","num_of_boxes":"","toll_consign_num":"","custId":"","venueId":"","bpay":"","proof_tracking_comments":"","veunue_comments":""}]" In the debug window of fire fox , in the post the results are [object Object] In the debug window of fire fox , in the response tab the results are string(17) "([object Object])" ([object Object])NULL string(17) "([object Object])" Quote Link to comment https://forums.phpfreaks.com/topic/194858-json-str-through-ajax-please-help/#findComment-1024595 Share on other sites More sharing options...
BrettCarr Posted March 11, 2010 Author Share Posted March 11, 2010 THIS WAS IN THE SOURCE CODE function addDatadb() { myarray = [{"batch_date":"1970-01-01","batch_number":"","original_proof_num":"596","batch_status":"New","invoice_num_ccaus":"","carrier":"Toll","num_of_boxes":"","toll_consign_num":"","custId":"","venueId":"","bpay":"","proof_tracking_comments":"","veunue_comments":""},{"batch_date":"2010-03-11","batch_number":"75752727","original_proof_num":"645","batch_status":"New","invoice_num_ccaus":"1","carrier":"Toll","num_of_boxes":"","toll_consign_num":"1","custId":"32","venueId":"202","bpay":"75272","proof_tracking_comments":"JFYJFYJHM","veunue_comments":"HTYJTYJTYJTYYJ"}]; send( '/ajax/arrayclean.php', 'myarray=' + myarray, null , null); alert(myarray); } Quote Link to comment https://forums.phpfreaks.com/topic/194858-json-str-through-ajax-please-help/#findComment-1024599 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.