php - How to convert stringified data to an object? -
my php has header('content-type: application/json')
, json_encode
.
ajax code use send data php file has datatype: 'json'
, sending data string (json.stringify
).
problem is, can't make $_post['data']
work on string.
way convert object?
edit: trying achieve is, sending data ajax php query looks information database , php file sends array using json ajax , ajax displays it.
ajax:
function op_prof(obj) { var xval = obj.id; $.ajax({ type: "post", url: '../script/profile.php', datatype: 'json', data: json.stringify({'u_search':'xval'}), cache: false, success: function(data) { console.log(data); alert(data); alert({u_search:xval}['u_search']); $("#co_profile").html(data).show(); } }); };
php:
<?php include(dirname(__file__). '/../script/config.php'); session_start(); $id = $_post['u_search']; foreach($pdo->query("select * users id='$id'") $row) { $fullname = $row['fullname']; $data = array("u_data"=> true,"inpt"=>"<p>my name " . $fullname . "</p>"); header('content-type: application/json'); echo json_encode($data); ?> <?php $pdo = null; ?>
i'd know other way of achieving (even without using json)
try json_decode("php://input");
Comments
Post a Comment