我需要一个简单的PHP函数来模仿Ajax表单提交 - 基本上是有一个单选按钮"ajax"的形式,它设置为是或否.我只需要模仿成功/失败的ajax调用......
HTML
<label for="">Ajax Success*<input type="radio" name="ajax" id="yes" value="yes" checked>Yes<input type="radio" name="ajax" id="no" value="no">No</label>
Run Code Online (Sandbox Code Playgroud)
PHP
<?php
$ajax = $_POST["ajax"];
if(isset($_POST['ajax'] == "yes")) {
echo "success";
} else {
echo "failure";
}
?>
Run Code Online (Sandbox Code Playgroud)
如果我删除了isset,我得到一个'未定义索引'错误,如果我把它放入我得到语法错误但它看起来对我来说是正确的...
我只需要根据为输入'ajax'选择的选项发回回声
谢谢
isset($_POST['ajax'] == "yes")没有意义.您想检查它是否已设置,然后检查其值是否等于"yes":
if(isset($_POST['ajax']) && $_POST['ajax'] == "yes") {
echo "success";
} else {
echo "failure";
}
Run Code Online (Sandbox Code Playgroud)