javascript - Unable to get JSON from Ajax POST using PHP -


i sending json in post php script. i'm unable object values json. format of post follows:

[{"name":"amount","value":"12"}]

javascript

("#idform").submit(function(e) {        var url = "post.php"; // script handle form input.       var formdata = json.stringify($("#idform").serializearray());       alert(formdata);        $.ajax({         type: "post",         url: url,         data: formdata,         datatype: 'json',         success: function(dataresponse) {           document.getelementbyid("orderamount").innerhtml = dataresponse.orderamount;         }       }); 

php

if(!empty($_server['http_x_requested_with']) && strtolower($_server['http_x_requested_with']) == 'xmlhttprequest') {  $data = array();  $json = json_decode(file_get_contents('php://input'), true); $data['orderamount'] = $json['amount']; //this works  //$data['orderamount'] = '12345';  echo json_encode($data);  } 

any idea i'm doing wrong?

we can parse json array, , dictionaries inside it, this,

<?php $json = "[{\"name\":\"amount\",\"value\":\"12\"}]"; $dec = json_decode($json,true);  for($idx = 0; $idx < count($dec); $idx++){     $obj = (array)$dec[$idx];     echo $obj["name"]; } ?> 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -