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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:42:14+00:00 2026-05-24T20:42:14+00:00

Does anyone know how to do this? I want to point $.getJson() to a

  • 0

Does anyone know how to do this?

I want to point $.getJson() to a controller and have it return json through ajax based on request arguments. Unfortunately it appears Zend handles the get parameters different than jQuery encodes them.

How can I do this with Zend and jQuery? I saw something on stackoverflow about Post arguments but I am lost when it comes to GET.

When using jQuery I get a 404 error using this code:


Client side:

$.getJSON("/entry/get-member-course",
{
    "id": 1,
    "format": "json"
},
function(json) {
    alert("WIN");
});

Server side:

public function init() {
    $this->_helper->ajaxContext->addActionContext('get-member-course', 'json')->initContext();
}

public function getMemberCourseAction() {
    $this->view->test = Array("test"=>"bleh");        
}
  • 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-24T20:42:15+00:00Added an answer on May 24, 2026 at 8:42 pm

    Easiest way is to use context switching. In your controller, setup the AjaxContext helper for your action with a “json” context

    class EntryController extends Zend_Controller_Action
    {
        public function init()
        {
            $this->_helper->ajaxContext->addActionContext('get-member-course', 'json')
                                       ->initContext();
        }
    
        public function getMemberCourseAction()
        {
            $id = $this->_getParam('id');
    
            $this->view->test = array('test' => 'bleh');
        }
    }
    

    The view for the calling script should contain a reference to the JSON URL. For example, say your JSON code is fired by clicking a link, create the link like this

    <a id="get-json" href="<?php echo $this->url(array(
        'action'     => 'get-member-course',
        'controller' => 'entry',
        'id'         => $someId
    ), null, true) ?>">Click me for JSON goodness</a>
    

    Your client-side code would have something like this

    $('#get-json').click(function() {
        var url = this.href;
        $.getJSON(url, {
            "format": "json" // this is required to trigger the JSON context
        }, function(data, textStatus, jqXHR) {
            // handle response here
        });
    });
    

    By default, when the JSON context is triggered, any view property is serialized as JSON and returned in the response. If your view properties cannot be simply converted, you need to disable automatic JSON serialization…

    $this->_helper->ajaxContext->addActionContext('my-action', 'json')
                               ->setAutoJsonSerialization(false)
                               ->initContext();
    

    and provide a JSON view script

    // controllers/my/my-action.json.phtml
    $simplifiedArray = array(
        'prop' => $this->someViewProperty->getSomeValue()
    );
    echo Zend_Json::encode($simplifiedArray);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know if SASS file extension is pretty much deprecated at this point
Does anyone know at what point this object is still available? I am trying
Does anyone know how to do this? Specifically I have two arrays and some
Does anyone know what this means. Getting this in C# winforms applications: Not a
Does anyone know what this value is for? If it is set to 1,
Does anyone know what this error message means? FATAL: Code generation error detected during
Does anyone know if this has been released yet? I went to asp.net and
Does anyone know why this code doesn't work. This means, the alert is NOT
Does anyone know if this subversion bug has been dealt with? https://svn.apache.org/repos/asf/subversion/tags/1.6.9/www/faq.html#windows-access-denied I'm getting
I cannot find this in the documentation anywhere. Does anyone know if this is

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.