This jquery function that sends a variable and retrieve data from a php file
function update(){
var nid = $("#identity").val();
//alert(nid);
$.getJSON('../js_backend/getComment.php', {n:nid},function(data){
$("#comment_view_spot").empty();
$.each(data.result, function(){
$("#comment_view_spot").append("<tr><td>"+this['username']+":</td><td>"+this['comment']+"</td></tr>");
});
});
}
below is the php file it works with, the problem am having is that it works fine when am not getting the variable i sent from the jquery
$result=array();
//$n=$_GET['n'];
$getJs=$connect->query("SELECT * FROM blog_comment");
while($rows=$getJs->fetch()){
array_push($result, array(
'username'=>$rows['username'],
'comment'=>$rows['comment']
));
}
header('Content-type: application/json');
echo json_encode(array("result" => $result));
but when am getting the variable it does not work fine if i try to go directly to the php file i see this bunch of codes
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: n in C:\wamp\www\ezoole\js_backend\getComment.php on line <i>6</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0004</td><td bgcolor='#eeeeec' align='right'>241728</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\ezoole\js_backend\getComment.php' bgcolor='#eeeeec'>..\getComment.php<b>:</b>0</td></tr>
</table></font>
please someone should help me resolve this.
{n:nid}to{"n::nid}it might work, otherwise just use the standard jquerypostapi.jquery.com/jquery.post$_GETin your PHP... you should use$_POSTinstead