【发布时间】:2016-03-16 17:37:26
【问题描述】:
我正在使用 JQuery 运行一个简单的 .get 语句:
$.get("check.php", function(data)
{
if (data == "yes")
{
$('#thisimg').attr('src' ,'yes.jpg');
}
else
{
$('#thisimg').attr('src' ,'no.jpg');
}
});
当我使用数据作为参数调用警报时,它返回“是”,但是 if 语句仍然没有运行并更改图像 src。
这是我的 check.php 文件:
<?php
//connect to db here
//run sql select statement to check whether or not the value is 0 or 1
//value is saved into variable $selected, and the value is 1
if ($selected == 1)
{
echo "yes";
}
else
{
echo "no";
}
?>
【问题讨论】:
-
在您的
console中记录data。console.log(data);. -
它输出“是”@brso05
-
console中是否有任何错误? -
数据的类型是什么?尝试 typeof(data) ,如果没有调用 if 语句(true 块或 else 块),则一定有错误。
标签: javascript php jquery sql