成功后,Ajax提交并将提交按钮替换为选中标记

时间:2019-01-15 17:31:36

标签: ajax cakephp cakephp-1.3

首先,我在cakephp 1.3环境中根本没有与ajax提交相关的运气。成功提交后,我希望用户停留在页面上,并隐藏或用复选标记替换提交按钮。我已经尝试了一些东西...没有$ action的控制器,然后是.click函数,而不是提交。我也不精通调试js,以查看错误之处,因此欢迎任何建议

也许“ update_a”是我的仪表板控制器中的$ action 改为使用“功能应用程序($ action){”?

仪表板控制器

function update_a($action) {
...
switch ($action) {
        case 'save':
if (!empty($this->data)) {
// update fields in database table matching model
$this->data['Model']['submitted'] = $_POST['submitted'];
$this->data['Model']['locked'] = $_POST['locked'];
if ($this->Model->save($this->data)) {
// save form fields to other models
$this->OtherModel->saveField('form_status_id',$_POST['form_status_id']);    
$this->OtherModel->saveField('form_status',$_POST['form_status']);
}
}
}
break;
default:
    //$this->redirect("admin/index");
    $this->render("dashboard/applications");
    break;
} //case
} // end function

html

<body>
<form id='update_a' action='save'>
<div class='form-group'>
<input type='hidden' class='hidden' name='locked' id='locked' value='1'>
<input type='hidden' class='hidden' name='form_status' id='form_status' value='Locked'>
<input type='hidden' class='hidden' name='form_status_id' id='form_status_id' value='3'>
<input type='hidden' class='hidden' name='submitted' id='submitted' value='<?php echo date("Y-m-d G:i:s") ?>'>
</div>
<div class='text-center'>
<input name='submit' type='button' class='btn btn-default' value='Submit Form A'>
</div>
</form> 
</body>
<script>
$(document).ready(function () {

        $('#update_a').on('submit', function (e) {
        //$('#update_a').click(function (e) {
          e.preventDefault();

          $.ajax({
            type: 'POST',
            url: '/dashboard/update_a',
            data: $('#update_a').serialize(),
            success: function () {
              alert('Form A has been submitted and locked for editing');
              $('#update_a').hide();
            },
            error : function() {
            alert("Error");
            }
          });
        return false;
        });

      });
</script>

0 个答案:

没有答案