How to display values returned by JSON

Codes here !

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 9
Joined: Wed Jul 03, 2013 10:14 pm

Thu Jul 04, 2013 7:41 am


I have written this . I want to display the values of firstname,lastname in HTML form

url: 'getdata.php', //the script to call to get data
data: "", //you can insert url argumnets here to pass to api.php
dataType: 'json', //data format
success: function(data) //on recieve of reply
var id = data[1]; //get id
var vname = data[2]; //get name
//alert (data[0]);



$query = "select firstname,middlename FROM emp_master WHERE id = 1";
$result = $mysqli->query( $query );
$row = $result->fetch_assoc();
$temp = array();
$temp['firstname'] = $row['firstname'];
$temp['middlename'] = $row['middlename'];
echo json_encode($temp);

<div class="myclassname" id = "Update">
<form method="post" action="getdata.php">
<input type="hidden" name="id" value="" />

<strong>First Name: *</strong> <input type="text" name="firstname" id="firstname"
<strong>Middle Name: *</strong> <input type="text" name="middlename" id="middlename"
/> <br/>

<p>* required</p>
<input type="button" name="submit" id="submit" value="Submit" />

php-forum Super User
php-forum Super User
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

Thu Jul 04, 2013 8:31 pm

I did not understand what you are trying to do as the script looks incomplete.

Usually json encoded values have to be passed through json_decode to decode it. Take a look at the manual.

Post Reply