【发布时间】:2015-11-18 14:17:19
【问题描述】:
我正在开发使用 CakePHP 作为后端和 JQuery 作为前端的 Web 应用程序。为了与服务器通信,我已经创建了表单和 jquery ajax 以及显示 ajax 向网络中的 url 发送请求值的浏览器。这是我现在拥有的:
问题
I want to display ajax post value into add.ctp which is not showing
第 1 页 Ajax 的工作原理
<script type="text/x-javascript">
$(".hover-star").click(function () {
$("#hover-test").css("color", "#ff6a00");
var id= $('input[name=starrating]:checked').attr('id');
$.ajax({
type: "POST",
url: '<?php echo Router::url(array('controller'=>'Reviews','action'=>'add'));?>',
cache: false,
data: "id="+id,
dataType: 'HTML',
success: function(result) {
window.open('/app/webroot/reviews/add/'+id,'_self');
},
error: function (response, desc, exception) {
// custom error
}
});
});
</script>
<form method="post">
<input class="hover-star" type="radio" name="starrating" id="1" value="1" title=""/>
<input class="hover-star" type="radio" name="starrating" id="2" value="3" title=""/>
<input class="hover-star" type="radio" name="starrating" id="3" value="3" title=""/>
</form>
第 2 页,我想在其中显示 ajax 请求值 Add.ctp
<?php echo $this->ratingPost;?>
评论控制器添加功能
function add()
{
$this->ratingPost= $data = $this->data;
}
【问题讨论】:
-
@AbrarKhan 没有错误,但 chrome 浏览器网络显示 ajax 发送了值,而在单击单选按钮后,
add.ctp文件中没有显示值