First time trying to use JSON. Here is my checklink.php :
function url_exists($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// $retcode > 400 -> not found, $retcode = 200, found.
if ($retcode == 400){
return "false";
}else{
return "true";
}
curl_close($ch);
}
$response = array(
'location' => $location,
'status' => $status
);
$rr = url_exists($response['location']);
echo json_encode( $rr );
JS part :
function UrlExistsNew(url, callback) {
$.getJSON('checklink.php', { location: url }, function ( data ) {
callback.apply( null, data.status );
});
}
...
UrlExistsNew($(this).val(), function(status){
if(status === "false") $(element).css('background-color','#FC0');
});
...
It seems the php page is not returning result to json query.
Edit : Note that I forgot to install curl and enable it in my server. I Hope no one miss this.