0
我使用ajax发送请求到一个php页面,该页面设置一个cookie并使用echo函数将消息发送回浏览器。但问题是,PHP成功设置cookie,但我没有收到消息回声。 我已经在控制台上记录了XMLHTTPRequest对象来确认。Ajax和PHP - 意外行为
这里是PHP代码:
<?php header("Access-Control-Allow-Origin: *");
session_start();
// echo "true"; - If I put the echo here , I get the response.
if(isset($_POST['init'])){
$x00 = universe::decode($_POST['init']);// Just a static function call of object Universe.
$_SESSION['id'] = $x00['id'];
echo "true"; // This echo does not appear in the response.
}
?>
这个responseText然而,这不是不确定的,这是一个空字符串。看看图片。
用'echo json_encode('true)替换'echo“true”;'' –
没有足够的信息。我相信你期待JSON格式的响应。但是,我们仍然不知道您打印的是什么。 – tilz0R
你的if语句没有执行... init参数不会与http请求一起发送ajax代码 –