【发布时间】:2017-12-03 07:44:35
【问题描述】:
Ajax 可以成功提醒 post 数据 ({"booking":{"testdata":"testdata"}})。问题是php代码无法获取$_POST。
js和php在同一个页面:localhost/booking/index.ctp
这是我的代码:
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.0.min.js"></script>
<script>
$.ajax({
url: "<?php echo $this->Url->build([
"controller" => "booking",
"action" => "index",
"_ext" => "ctp",
true
]);?>", //This is the current doc
type: "POST",
dataType:'json',
data: {'testdata': 'testdata'} ,
success: function(data){
// console.log(data);
alert(JSON.stringify(data));
}
});
</script>
<?php
if (isset($_POST['testdata'])){
$getv = $_POST['testdata'];
echo json_encode($getv);
}
else {
echo "none";
}
?>
【问题讨论】:
-
你到底想用这段代码实现什么?
标签: javascript php ajax cakephp