【发布时间】:2020-08-25 03:27:39
【问题描述】:
我对 test.php 进行了 ajax 调用,甚至在 devtools network 中显示调用成功。
问题是即使在成功调用之后,$country 也不会被回显。
这是我的代码
ajax.php
<!DOCTYPE html>
<html>
<head>
<title>Interval</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$.ajax({url: 'test.php',
data: {value: 'India'},
type: 'post',
success : function(data){
alert(data);
}
});
</script>
</head>
<body>
</body>
</html>
test.php
<?php
if(isset($_POST['value']) && $_POST['value'] == 'India'){
$country = $_POST['value'];
echo $country;
}
?>
【问题讨论】:
-
请记住,您使用 AJAX,因此您不必刷新页面。把被javascript AJAX代码调用的PHP做成一个单独的文件,然后
echo $country;,然后从success function(response){ alert($response);}的js代码中得到它 -
不工作仍然没有错误,但它也不会回显输出。
-
查看我编辑的代码。