View Full Version : get json result from php to ext js

28 Dec 2010, 7:40 PM
Hi guys,

I need your little help in my little understanding of json object.

Here is the result output from my login page.

My aim is to get the user Id return from json object but when i echo

echo json_encode($result);- > this is the return values... it goes to failure function in ext js UI
Access Denied : [{"userId":"15","0":"15","username":"eadeloso","1":"eadeloso","password":"12345","2":"12345"}]

if I put this two:
echo '{"success":"true"}' ;
echo json_encode($result);

an error will occurs.

My question are:
1. How can return the json result with success = true so that it will be catch in success funtion of my UI.
2. How can get the json object or data for the userId only.

I just need to get the userId here like for the example data userid is 15.

thanks for any help.

29 Dec 2010, 1:43 AM
GWT has a JSONArray class which you can use for "[{"userId":"15","0":"15","username":"eadeloso","1":"eadeloso","password":"12345","2":"12345"}] "

29 Dec 2010, 1:51 AM
i was able to read the data :

var x = Ext.util.JSON.decode(obj.response.responseText.trim())
var id = x.data[0].userId;

29 Dec 2010, 1:54 AM
You are not using GXT but ExtJS

29 Dec 2010, 6:21 AM
(php) json_encode expects what it is "encoding" to be an array type. You can't use that function to create a json string...from a json string.

var $result = array( "success" => true ) ;
echo json_encode( $result ) ;