please your help, i have problem in my ajax request. i have return text data and i want to convert it to JSON using json_parse but it does't work
the data that return from the ajax request looks like this :
data = "{"name":"ehab","mobile":"xxx"}{"name":"Hamza","mobile":"zzzz"}"
i want to convert this data to json i use the following ajax request
$.ajax({
type: "POST",
url: "getGroup.php",
data: { "searchText" : number},
success: function(data)
{
data = JSON.parse(data);
debugger;
},
error: function (error) {
debugger;
}
if i use this way error message returns
Uncaught SyntaxError: Unexpected token {
my php array file
$sql ="select * from recipients where `groupid`='$searchText'";
$res = mysql_query($sql);
$num = mysql_num_rows($res);
$data='';
if(mysql_num_rows($res)> 0)
{
for($i=0;$i<mysql_num_rows($res);$i++) {
$row=mysql_fetch_assoc($res);
$output = array('name'=>$row['rec_name'],
'mobile'=>$row['mobile_number']);
echo json_encode($output);
}
please advice