0

我正在使用 AJAX 调用将值传递给 PHP 并从 PHP 中检索值。我在控制台中得到的输出是 NaN 我不知道这意味着什么。请帮我纠正这个问题并使用 AJAX 取回价值

脚本代码:

window['channel']="OVERALL";
     $.ajax({
             method:"GET",
             url:"dash2.php",
             data:({channel:+channel}),
             success:function(data){
                    alert(data);
                    //console.log(data);
                    }
            });

PHP代码:

<?php

$channel=$_GET['channel'];

echo json_encode($channel);



?>
4

4 回答 4

3

NaN 表示不是数字..

为什么+那里有操作员

data:({channel:+channel}), //here this is trying to convert it into number hence resulting in NAN

它应该是

data:({channel:channel}), 

大胆猜测,应该是(如果您尝试将其传递给服务器端(PHP)

data:{channel: window['channel']},
于 2013-03-27T11:10:46.120 回答
2
+channel

+尝试将“OVERALL”转换为数字(结果为 NaN)

于 2013-03-27T11:10:50.807 回答
0

代替:

data:({channel: +channel}),

尝试这个:

data:{channel: channel},
于 2013-03-27T11:11:43.593 回答
0

提供 JSON 数据类型并检查。

$.ajax({
    type:"GET",
    url:"dash2.php",
    dataType: 'json',
    data:({channel:+channel}),
    success:function(data){
        alert(data);
        //console.log(data);
    }
});
于 2013-03-27T11:12:32.910 回答