我正在使用CakePHP作爲後端,JQuery作爲前端的Web應用程序。爲了與服務器進行通信,我已經創建了表單和jQuery Ajax以及顯示Ajax向網絡中的url發送請求值的瀏覽器。以下是我現在所擁有的:Jquery Ajax Post到CakePHP控制器
問題
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請求的值添加。 ctp
<?php echo $this->ratingPost;?>
評論控制器添加功能
function add()
{
$this->ratingPost= $data = $this->data;
}
什麼錯誤? –
@AbrarKhan沒有錯誤,但鉻瀏覽器網絡顯示,在點擊單選按鈕 –