由於某種原因,如果我將表單元素更改爲隱藏,我的ajax表單不起作用。如果我將它們改爲輸入,它確實如此。爲什麼會這樣?爲什麼我的ajax請求不能使用隱藏的AJAX表單輸入CakePHP 2.3
這裏是視圖
<div id="price">
<?php
$this->Js->get('#phonepricearea');
echo $this->Form->create('offer', array('url' => '/PhoneKarma/PhoneQueries/ajaxOffer', 'class' => 'custom'));
echo $this->Form->hidden('phoneCapacity',array('value'=>''));
echo $this->Form->hidden('phoneCondition',array('value'=>''));
echo $this->Form->hidden('carrier',array('value'=>''));
echo $this->Js->submit('Check', array('class' => 'button expand',
'title' => 'Check',
'url' => array(
'action' => 'ajaxOffer'
),
'update' => '#price'
));
echo $this->Form->end();
?></div>
控制器
public function ajaxOffer($capacity=null, $condition = null , $carrier = null) {
if (!empty($this->data) && $this->request->is('ajax')) {
//do stuff this doesn't effect the code..
$this->render('ajaxOffer', 'ajax');
} else {
$this->set('offer', "0");
}
}
Javascript來改變值
$('#offerPhoneCapacity').val(id);
你有沒有嘗試調試與螢火蟲或谷歌Chrome瀏覽器開發的應用工具? – kentverger 2013-05-01 04:23:52
是它給我「無法加載資源:服務器響應狀態爲400(錯誤請求)」 – 2013-05-01 04:30:15
發佈您的ajax和控制器功能 – Preetam 2013-05-01 04:45:45