javascript - Cannot detect json_encode result from mysql in ajax success -
i trying json response in success ajax mysql.
error getting in console -> uncaught syntaxerror: unexpected token <
my ajax code.
function getmessage(siteid) { document.getelementbyid("add").disabled = true; $.ajax({ type: "post", url: "checksite.php", data: { siteid : siteid }, //6 digit number success: function(data) { alert(data); var obj = jquery.parsejson(data); if(objdata.status == "not available"){ alert("not available"); document.getelementbyid("add").disabled = false; } if(objdata.status == "available"){ alert("available"); document.getelementbyid("add").disabled = false; } }, error: function(result){ alert("error"); } }); }
my checksite.php
$siteid = $_post['siteid']; if($siteid !=''){ $sql = "select * tablename siteid='$siteid'"; $result2 = mysql_query($sql); if(mysql_num_rows($result2) > 0){ echo json_encode(array('status' => 'not available')); } else{ echo json_encode(array('status' => 'available')); } }
its showing me parse error. jquery.parsejson(data)
not @ working.
there syntax error on line
data: { siteid : siteid }
add comma @ end
data: { siteid : siteid }, ^
Comments
Post a Comment