[英]Weird AJAX error: not getting a response on AJAX call while getting a response when doing the exact call with different values
I have an admin panel in which I want to update the order status to pending/done with a radio button on each order. 我有一个管理面板,我想在其中将每个订单的单选按钮的订单状态更新为待处理/完成。
Here is my HTML: 这是我的HTML:
<td><form class="radio">
<label><input type="radio" name="radio" value="0" checked="checked" data-id="42">Pending</label>
<label><input type="radio" name="radio" value="1" data-id="42">Done</label>
</form></td>
Here is the JavaScript: 这是JavaScript:
$("input[type='radio']").click(function() {
var radio = $(this).val();
var id = $(this).data("id");
$.ajax({url: "functions.php?radio=" + radio + "&id=" + id, success: function(result){
alert(result);
}});
});
And here is my PHP: 这是我的PHP:
if($_GET['radio']) {
$query = "UPDATE `kvitel` SET `status`= ".$_GET['radio']." WHERE `id`= " . $_GET['id'] . " LIMIT 1";
if ($conn->query($query) === TRUE) {
echo 1;
} else {
echo 2;
}
}
When I press on the 'Done' radio button everything works fine, but when I try to press the 'Pending' radio button I get an empty AJAX response and the database does not get updated. 当我按下“完成”单选按钮时,一切正常,但是当我尝试按下“待定”单选按钮时,我得到一个空的AJAX响应,并且数据库未更新。
Can anyone help me with this please??? 谁能帮我这个忙吗???
您的问题是此value="0"
, PHP
的if
语句失败,因为它变为0
,为false
if($_GET['radio']) { // GET value is 0, this fails.
Try changing: 尝试更改:
if($_GET['radio'])
to 至
if(isset($_GET['radio']))
If you look if(variable)
your are checking a boolean, 0 means false so it should not enter in that branch 如果您查看
if(variable)
您正在检查布尔值,则0表示false,因此不应在该分支中输入
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.