duanliushua5026 2013-06-24 13:54
浏览 63

Zend PHP简单的AJAX

I've searched SO for an answer to this, and even though I can find answers relating to the Zend framework and AJAX, I am not able to fix my problem.

I want to do delete a table row via an AJAX POST method.

My reason for doing this is that my web developer can longer make changes to my project, so I am having to step in and attempt to do some things myself (so I'll overlook somewhat obvious things).

HTML:

<a class="btn btn-danger delete_request_button" data-rid="<?php echo $row['id']?>" data-did="<?php echo $row['dealer_id']?>" href="#delete_request_button" data-toggle="modal">Delete</a>

jQuery:

jQuery('.delete_request_button').click(function(){
    var id = jQuery(this).attr('data-rid');
    jQuery('#request_id').val(id);

    jQuery.post('<?php echo $this->baseUrl("requests/delete")?>', { id: id }, function(response) {

    }).complete(function(){
        alert(id + ' deleted')
    });
});

Controller:

function deleteAction() 
{
    $id = $this->getRequest()->getParam('id');
    if($request->isPost()) {
        $this->model_dealer->deleteRequest($id);
        exit();
    }
}

Model:

public function deleteRequest($id)
{
    $where = $db->quoteInto('id = ?', $id);

    $db->delete('dealers_vehicle_requests', $where);
}

And here is my table:

CREATE TABLE `dealers_vehicle_requests` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `dealer_id` bigint(20) DEFAULT NULL,
  `message` text,
  `requested_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `status` char(1) DEFAULT 'P',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

I realise that this is probably a mashup of horrible code, but I'm using SO as a last resort to try and solve this problem.

Thanks!


Edit: fixed

Model:

public function deleteRequest($id)
{
    $where = $this->dealers_subscriptions->getAdapter()->quoteInto('id = ?', $id);
    $this->dealers_vehicle_requests->update(array('status' => 'D'), $where);
}

Controller:

function deleteAction() 
{
    $request = $this->_request;
    $id = $request->getParam('id');

    if($request->isPost()) {
        $this->model_dealer->deleteRequest($id);
        exit();
    }
}

Everything else kept the same.

Thanks to all that helped with this question.

  • 写回答

1条回答 默认 最新

  • dongliu5475 2013-06-24 13:57
    关注
    public function deleteRequest($id)
    {
        $where = $db->quoteInto('id = ?', $id);
    
        $db->delete('dealers_vehicle_requests', $where);
    }
    

    Did you forget to initialize $db variable there ?

    Try to add:

    $db = Zend_Db_Table::getDefaultAdapter();

    EDIT

    Also try this JS :

    jQuery('.delete_request_button').click(function(){
        var id = jQuery(this).attr('data-rid');
        jQuery('#request_id').val(id);
    
        jQuery.post('<?php echo $this->baseUrl("requests/delete")?>', { id: id }, function(response) {
            alert(id + ' deleted')
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?