2014-10-11 66 views
0

我想通过ajax添加数据而不使用ajax helper.Here插入工作正常,但问题是插入数据后,我没有看到成功massage.Here是我的努力。Cakephp ajax插入不使用蛋糕ajaxhelper

<script> 
$(document).ready(function(){ 
$('#submit').click(function(){ 
     x=$("#rform").serializeArray(); 
     $.post($("#rform").attr("action"), 
       x, 
       function(data) 
       { 

        $("#success").html(data); 
        $("#success").fadeIn(); 
        $("#success").fadeOut(2800); 
        $("input").val(''); 
       }); 
     $("#rform").submit(function(){ 
      return false; 
     }); 
}); 

}); 

</script> 

这里是add.ctp代码

<?php 

    echo $this->Form->create('Info',array(
     'id' => 'rform' 
     )); ?> 
    <fieldset> 
     <legend><?php echo __('Add Info'); ?></legend> 
    <?php 
     echo $this->Form->input('name'); 
     echo $this->Form->input('email'); 
    ?> 
    </fieldset> 
    <?php 
$options = array 
(
    'label' => 'Add', 
    'value' => 'Add', 
    'id' => 'submit' 

); 
echo $this->Form->end($options); 
?> 
</div> 
<div style="color:green;" id="success"> 

</div> 

这里之后将其添加在bellow.Here再次重复插入页面我需要证明只有成功,我massage.If删除$("#success").html(data);什么也没有发生,但插入按钮名称后消失。如何在此处添加成功按摩?

+0

莫非你在#submit div中添加一些文本并检查它是否可见?无需提交表单。只需刷新。 – 2014-10-11 16:14:52

+0

您也可以发布服务器上用于处理此请求的方法中的代码 – 2014-10-11 16:22:42

回答

0

我已经有点变化解决它

$("#success").html(data); 

$("#success").html("Insert Success"); 

,在这里我已经改变了输入按钮的标签,我在这里使用直接按钮

<button id="submit">Submit </button>