Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6021385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:42:18+00:00 2026-05-23T03:42:18+00:00

My Zend controller is like below: public function deleteAction() { $this->_helper->layout->disableLayout(); $id = (int)$this->_request->getPost(‘id’);

  • 0

My Zend controller is like below:

 public function deleteAction()
    {
        $this->_helper->layout->disableLayout();
         $id = (int)$this->_request->getPost('id');
        $costs = new Application_Model_DbTable_Costs();
        if($costs->deleteCosts($id)){
            $this->view->success = "deleted";
        }

    }

And ajax call I ma using to post data is :

 $.ajax({
             dataType: 'json',
            url: 'index/delete',
            type: 'POST',
            data:id,
            success: function () {
             alert("success");
            },

            timeout: 13*60*1000,
            error: function(){
               console.log("Error");
            }

        });

And in my delete.phtml the code is like:

<?php 
    if($this->delete === true): 
        echo 'true';
    else:
        echo 'Sorry! we couldn\'t remove the source. Please try again.';
    endif;
?>

The response is returning the html.

Its my first project with Zend Framework.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:42:19+00:00Added an answer on May 23, 2026 at 3:42 am

    Your controller action is returning HTML, not JSON.

    You should consider using the AjaxContext action helper

    public function init()
    {
        $this->_helper->ajaxContext->addActionContext('delete', 'json')
                                   ->initContext();
    }
    
    public function deleteAction()
    {
        $id = (int)$this->_request->getPost('id');
        $costs = new Application_Model_DbTable_Costs();
        try {
            $costs->deleteCosts($id));
            $this->view->success = "deleted";
        } catch (Exception $ex) {
            $this->view->error = $ex->getMessage();
        }    
    }
    

    The only other thing you need to do here is supply a format parameter of json in the AJAX request, eg

    $.post('index/delete', { "id": id, "format": "json" }, function(data) {
        if (data.error) alert("Error: " + data.error);
        if (data.success) alert("Success: " + data.success);
    }, "json");
    

    You may want to handle the response differently but that should give you an idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've something like <?php class AccountController extends Zend_Controller_Action { public function init() { if(!Zend_Auth::getInstance()->hasIdentity())
Sorry for constantly re-editing my question but looks like this is the only way
i have been using a modular structure for my zend framework application. This is
i create 3 module for my proj like this: application/module/admin application/module/default application/module/error every module
I'm using the zend framework and have started setting up really easy urls. I'm
I would like to know the differences between two helpers Zend_Controller_Action_Helper_Abstract and Zend_View_Helper_Abstract in
I'd like to set up multiple domain names to use the same framework, but
i am working on a zend framework application, and to my surprise, the default
i am using a modular architecture with Zend framework, and i want to use
I'm trying to create a mod rewrite expression to redirect from localhost/1234 to localhost/controller/action?param=1234.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.