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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:39:25+00:00 2026-05-24T21:39:25+00:00

So I have my JavaScript making an Ajax call to /my_controller/ajax_action but then in

  • 0

So I have my JavaScript making an Ajax call to /my_controller/ajax_action but then in the controller I don’t know what to do to output something back to the JavaScript.

I am getting errors because there is no view for MyController::ajaxAction() but obviously there is no view for it, so what do I do?

  • 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-24T21:39:26+00:00Added an answer on May 24, 2026 at 9:39 pm

    do this, have your variables you want to output in an array let’s say $data, then pass that array to the view using the $this->set('data', $data); method, then create a view /General/SerializeJson.ctp. In that view file, put <?PHP echo json_encode($data); ?> after that you can use $this->render('/General/SerializeJson'); and it should output the json.

    General code…

    /Controllers/MyController.php

    public class MyController extends AppController
    {
        public function ajaxAction()
        {
            $data = Array(
                "name" => "Saad Imran",
                "age" => 19
            );
            $this->set('data', $data);
            $this->render('/General/SerializeJson/');
        }
    }
    

    /Views/General/SerializeJson.ctp

    <?PHP echo json_encode($data); ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some javascript making an ajax call in my Rails site: $.ajax({type: PUT,
I have a web application, in which I'm making an AJAX call to fetch
When I am making an ajax call the controller is redirecting and not updating
I have a standard javascript ajax call where I'm setting the data: to json
I am making a small calculator (just for JavaScript learning) and I have two
I am making a webapp. I have a fairly basic question about javascript performance.
I'm searching for a better solution to making an AJAX call with jQuery, having
I have a view that contains a javascript function that i need to init/call
I'm making an AJAX call which returns XML data, and this is my 'success:'
I have some jQuery code in an external Javascript file that is making an

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.