I am using AJAX call to pass a value to PHP and retrieve a value from PHP. The output i am getting in the console is NaN i am not aware what this means. Please help me rectify this and get the value back using AJAX
Script code:
window['channel']="OVERALL";
$.ajax({
method:"GET",
url:"dash2.php",
data:({channel:+channel}),
success:function(data){
alert(data);
//console.log(data);
}
});
PHP code:
<?php
$channel=$_GET['channel'];
echo json_encode($channel);
?>
NaN mean Not a Number..
why do you have +
operator there
data:({channel:+channel}), //here this is trying to convert it into number hence resulting in NAN
it should be
data:({channel:channel}),
taking a wild guess, it should be(if you are tryto pass that to server side (PHP)
data:{channel: window['channel']},
+channel
+
tries to convert "OVERALL" to number (result is NaN)
Instead of:
data:({channel: +channel}),
Try this:
data:{channel: channel},
Provide JSON datatype and check.
$.ajax({
type:"GET",
url:"dash2.php",
dataType: 'json',
data:({channel:+channel}),
success:function(data){
alert(data);
//console.log(data);
}
});