[英]I post with ajax in the same page but i can't receive in php
I would post in the same page. 我会在同一页面上发帖。 For this i post with ajax.
为此,我用ajax发布。 But i post and receive in the same page.
但是我在同一页面上发布和接收。
The code : 编码 :
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
$("#menusecme1").on("change", function() {
var deger = $("#menusecme1").val();
$.ajax({
url: "okulue.php",
type: "POST",
data: {
menu : deger
},
success: function(){
}
});
});
</script>
İn success i created an alert function it working. 成功后,我创建了一个警报功能,它可以正常工作。 So in this code have any problem.
因此在此代码中有任何问题。
The php code: php代码:
if (isset($_POST["menu"]) == 'yes') {
}
if (isset($_POST["menu"])) {
}
I tried this if. 我尝试过这个。 But they not work.
但是它们不起作用。
How can i resolve this problem? 我该如何解决这个问题?
I need your help. 我需要你的帮助。
isset()
returns boolean and not what you have. isset()
返回布尔值,而不是您所拥有的。
Below will help you test. 下面将帮助您测试。
in php script, do this 在php脚本中,执行此操作
echo isset($_POST['menu']) ? 'yes' : 'no';
This will echo out yes should $_POST['menu']
be set 如果设置了
$_POST['menu']
它将回显是
Personally i would go for empty()
as it also checks if the variable is also set. 就个人而言,我会选择
empty()
因为它还会检查是否也设置了变量。
echo !empty($_POST['menu']) ? 'yes' : 'no';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.