I am trying to generate some JSON data that can be read from a page using ajax. I found some threads that recommend that I use the following format to create the data.
echo CJSON::encode(array(
"first_name" => $profile->first_name,
"last_name" => $profile->last_name,
"photo_url" => Yii::app()->request->getBaseUrl(true).'/assets/pic/thumb/'.$profile->profile_image,
));
I get the following results:
{
"first_name": "Application",
"last_name": "Admin",
"photo_url": "1.jpg"
}
I am trying to read it using this code:
$.ajax({
url: "http://127.0.0.1/spark/index.php/participantreg/getProfileJSON",
crossDomain: true,
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
//force to handle it as text
//dataType: "text",
success: function(data) {
//console.log('success in updatProfile js');
//data downloaded so we call parseJSON function
//and pass downloaded data
var json = $.parseJSON(data);
//now json variable contains data in json format
//let's display a few items
$("#form_first_name").text(json.first_name);
$("#form_last_name").text(json.last_name);
},
error: function(xhr, status, error) {
alert('Error !!'+status+error);
},
async: false,
cache: false
});
};
I keep getting a parse error, not sure why.