cakephp ajax不工作

时间:2011-09-07 10:25:56

标签: cakephp cakephp-1.3

我的ctp中有2个ajax表单, 一个是工作而另一个不工作,而是被重定向。

这是我的.ctp文件

<div>
            <?php  echo $ajax->form('deletecreativeschedule','post',array('id'=>'delete','model'=>'admin','update'=>'myTable')); ?>                
            <input type="hidden" id="deviceid" name="deviceid" value="<?php echo $device['Device']['id'] ?>" />
             <input type="hidden" name="scheduleid" id="scheduleid"/>
             <input name="btnDelete" type="image" src="/<?php echo $site_root ?>/img/btnDelete.gif" height="16" class="sbtnDelete"  id="sbtnDelete" onclick="return deleteSchedule();"  title="Delete creative" >
            <?php echo $form->end(); ?>

            <br>
            <?php  echo $ajax->form('swapcreativeschedule','post',array('id'=>'swap','controller'=>'admin','update'=>'myTable')); ?>                
            <input type="hidden" id="deviceid" name="deviceid" value="<?php echo $device['Device']['id'] ?>" />                 
             <input type="hidden" name="aIdAjax" id="aIdAjax"/>
             <input type="hidden" name="aSeqAjax" id="aSeqAjax"/>


           <input name="btnUP" type="image" src="/<?php echo $site_root ?>/img/up.png" class="sbtnup"  id="sbtnup" onclick="return SwapRow('0');"  title="Delete creative" >
            <input name="btnDown" type="image" src="/<?php echo $site_root ?>/img/down.png" class="sbtndown"  id="sbtnup" onclick="return SwapRow('1');"  title="Delete creative" >
            <?php echo $form->end(); ?>

并在控制器中:

function deletecreativeschedule()
{
$this->autorender = false;
    $this->layout = 'ajax';
}
function swapcreativeschedule()
{
$this->autorender = false;
    $this->layout = 'ajax';
}

在views / admin文件夹中我创建了文件deletecreativeschedule.ctp和swapcreativeschedule.ctp

ajax对deleteschedule工作正常 但是对于swapcreativeschedule,它会重定向到/ admin / swapcreativeschedule

这里有什么问题?

1 个答案:

答案 0 :(得分:0)

我希望它能运作,

  <?php  echo $form->create('deletecreativeschedule'); ?>                
        <input type="hidden" id="deviceid" name="deviceid" value="<?php echo $device['Device']['id'] ?>" />
         <input type="hidden" name="scheduleid" id="scheduleid"/>
         <input name="btnDelete" type="image" src="/<?php echo $site_root ?>/img/btnDelete.gif" height="16" class="sbtnDelete"  id="sbtnDelete" onclick="return deleteSchedule();"  title="Delete creative" >
         <? echo $ajax->submit('btnDelete.gif',array("url"=>array('controller'=>'your controller','action'=>'ur action',$device['Device']['id']),'class'=>'sbtnDelete','update'=>'ur updateDiv') ?>
<?php echo $form->end(); ?>


<br>
 <?php  echo $form->create('swapcreativeschedule'); ?>                
        <input type="hidden" id="deviceid" name="deviceid" value="<?php echo $device['Device']['id'] ?>" />                 
         <input type="hidden" name="aIdAjax" id="aIdAjax"/>
         <input type="hidden" name="aSeqAjax" id="aSeqAjax"/>

<? echo $ajax->submit('up.png',array("url"=>array('controller'=>'your controller','action'=>'ur action',$device['Device']['id']),'class'=>'sbtnup','update'=>'ur updateDiv') ?>
<? echo $ajax->submit('down.png',array("url"=>array('controller'=>'your controller','action'=>'ur action',$device['Device']['id']),'class'=>'sbtndown','update'=>'ur updateDiv') ?>

 <?php echo $form->end(); ?>