2

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.

4
  • Can you access the data in JavaScript as such? w.document.write("FirstName"+data['firstname']) Commented Aug 7, 2012 at 18:17
  • That's because the default string representation of objects is [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. Commented Aug 7, 2012 at 18:35
  • Duplicate of stackoverflow.com/questions/464188/json-in-jquery. Commented Aug 7, 2012 at 18:39
  • @cds Consider console.log(data) to help decipher what is being returned from the json request. Commented Aug 7, 2012 at 18:56

1 Answer 1

2
success: function(data) { var emailid = data.rows[0].emailid; var vname = data.rows[0].firstname; var vlaname=data.rows[0].lastname; var w = window.open('', 'Feedback', 'width=400,height=400,resizeable,scrollbars'); w.document.write("FirstName"+data.rows[0].firstname); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.