My HTML/jQuery Code
<div id="divResult"></div>
function doSearch(str){
var jsonString = str;//$.parseJSON//JSON.stringify(str);
$.ajax({
type:'GET',
url:'search.php',
data:{data:jsonString},
success:function(data){
for( var key in data ) {
alert(key);
}
});
}
My problem is that when I tried to parse the JSON (display it) I'm not getting the expected result, The data gets displyed in a manner of per text per line eg.
The JSON data was [{"userid:1,name:paul"},{"userid:5,name:jackson"}]
The display on the browser is like this,
[
{
"
u
s
e
r
i
d
:
1
and so on so forth...
I can't understand? is there something wrong?
I tried my js code with jsFiddle and it looks good,
I expect something like these;
1 Paul
5 Jackson
PHP Code is;
if ($stmt->execute(array("%$_GET[data]%"))) {
while ($row = $stmt->fetch()) {
$aResult[] = array(
'userid' => $row['ui_userid'],
'category' => $row['ui_jocategory']
);
//print_r($aResult);
}
echo json_encode($aResult);
}
Thanks in advance..