jquery - PHP & JSON - Trouble to print a value on client side -
i have php function :
if(($_post['id']=="pm_read") && (isset($_post['pm_id'])) && (ctype_digit($_post['pm_id'])) && (isset($_session['nickname']))) { $update=mysql_query("update pm set readed='1' id='".$_post['pm_id']."' , receiver='".$_session['nickname']."'",$mydb); $query=mysql_query("select count(id) pm receiver='".$_session['nickname']."' , readed='0' , receiver_delete='0' order date desc",$mydb); $arraypm[0]=mysql_result($query,0,'count(id)'); $query=mysql_query("select message pm id='".$_post['pm_id']."' , receiver='".$_session['nickname']."'",$mydb); $arraypm[1]=mysql_result($query,0,'message'); echo json_encode($arraypm); }
on client side, array trought jquery function :
$.ajax({ type: 'post', cache: false, url: 'pm/pm_ajax.php', data: 'pm_id='+$(this).attr('id')+'&id=pm_read', success: function(data) { ... here i'll print somethings... } });
unfortunatly, if print data
(for example) string ["2", "message"]. so, if try alert(data[0]) i'll see [.
how can access array printing correct result? mean :
data[0] must print 2 , data[1] must print message...
try adding
datatype:'json'
to options in ajax call.
Comments
Post a Comment