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 7707533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:23:05+00:00 2026-06-01T00:23:05+00:00

I want to make delete action asynchronous using AJAX, in the controller I make

  • 0

I want to make delete action asynchronous using AJAX, in the controller I make an action that handle the request

  public function deleteAction() {

    $request = $this->getRequest();
    if ($request) {
        $visitId = $request->getParam('visit_id');
        $mapper = new Visits_Model_VisitsMapper();
        try {
            $mapper->deleteVisit($visitId);
           echo json_encode("1");
        } catch (Exception $e) {
            $this->view->message = "error inserting Data, Error details: " . $e->getMessage();
          echo  json_encode("0");
        }

        Zend_Controller_Front::getInstance()->setParam('noViewRenderer', true);
    }
}

and in the jquery script

 $("a.delete").live('click',function(e){
    e.preventDefault();
   var data={
                "visit_id":$(this).parent().parent().attr("id")
     };

    jQuery.ajax({
        url: "/visits/visit/delete",
        type: "POST",
        dataType: 'json',
        data: requestDate,
        success: successCallback,
        error:failureCallback
   });

When I click on delete button, the request is sent and an error on pop up occur

 Error    <!-- application/layouts/scripts/layout.phtml -->
 the  whole html of layout page....
 error SyntaxError: JSON.parse: unexpected character

I detect that the delete process does not happened!!
When I send synchronous request the delete operation happened successfully. And also when I make the AJAX call without using Layout page the delete is succeeded successfully also.

What can be the error?

  • 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-06-01T00:23:06+00:00Added an answer on June 1, 2026 at 12:23 am

    I suspect your layout is rendered and then is getting parsed (unsuccessfully) by the jQuery code. Try turning it off:

    try {
        $mapper->deleteVisit($visitId);
        if ($this->getRequest->isXmlHttpRequest()) {
            $this->_helper->json("1"); //this will disable layout and view renderer
                                       //and echo your data
        }
        else {
            //...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a little application. That will have register, save, update, delete,
I'm trying to make Jquery delete function, here is the code, that I wrote
I want make datetimepicker in my project. Using jquery how it is possible? I
I am traversing a HTML document using javascript DOM. I want make a list
I have link for example domain.com/de/controler/action?param=value and I want make actionlink to keep same
I'm trying to make a delete confirmation action sheet like what you see in
I want to delete my task ajax-style if some conditions are met. I do
I want to make some file operation using Javascript or jQuery like: File create
I want to make text area, where always is pre written text, and that
I want make a bash script which returns the position of an element from

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.