I just want to know how to get the json data in phtml file. Below is my php controller.
foreach($result AS $row) {
$arrValues[] = array("firstname"=>$row['firstname'],
"emailid"=>$row['emailid'],
"lastname"=>$row['lastname']);
}
header("Content-type: application/json", true);
echo json_encode(array('rows'=>$arrValues));
This is my phtml file.
var emailid=$(this).data('emailid');
//alert(emailid);
$.ajax({
url: 'http://localhost/feedback/public/index/email/',
type: 'POST',
data: {emaildata: emailid },
dataType: 'json',
success: function(data) {
var emailid = data[0];
var vname = data[1];
var vlaname=data[2];
var w = window.open('', 'Feedback', 'width=400,height=400,resizeable,scrollbars');
w.document.write("FirstName"+data[0]);
}
});
Im trying to write those values in apop up window.But it says object.Could you please help me how to get the json data and write that in to popwindow.
[object Object]. Access the properties of the objects to get the actual values. If you don't know how, have a look at developer.mozilla.org/en-US/docs/JavaScript/Guide/…. Also, when you post code and you expect us to read it, please format it properly.console.log(data)to help decipher what is being returned from thejsonrequest.