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

  • Home
  • SEARCH
  • 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 7929297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:01:33+00:00 2026-06-03T20:01:33+00:00

I am trying to retrieve some data using a combination of jQuery and CakePHP.

  • 0

I am trying to retrieve some data using a combination of jQuery and CakePHP.

I have a feed() method that sends the data back from the database JSON-encoded. The method works fine when I visit the URL using the browser.

function feed($id = null) {
    $this->layout = 'ajax';
    $data = array(
        'test' => true
    );
    echo (json_encode($data));
}

I also have a method that should retrieve the data, but for some reason it isn’t.

var address = '/person_availabilities/feed/1';

// JavaScript Document

$(document).ready(function() {
    var events = doAJAXcall(address);
    alert(events)
}


function doAJAXcall(url) {
    $.ajax({
        type : 'POST',
        url : url,
        dataType : 'json',
        data: {
        },
        success : function(data){
            return data;
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            //$('#login_error').show();
        }
    });
}

I suspect that the URL may be wrong, as xdebug does not pick the request up.

Does anyone have any suggestions for me? I’ve been looking for over four hours now.

EDIT: this is the address of the page localhost/Testing/person_availabilities/feed

  • 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-03T20:01:35+00:00Added an answer on June 3, 2026 at 8:01 pm

    There are two problems that I see with your AJAX request. The first one requires an understanding that AJAX requests are by their very nature asynchronous; hence, the acronym AJAX stands for Asynchronous JavaScript and XML. The asynchronous component is the key thing one must understand.

    You have a function where you are sending an AJAX request to the server, but in your success callback function, you are making an attempt to return a value. You cannot do this, because the function actually returns long before the success callback is fired.

    function doAJAXcall(url, callback) {
        $.ajax({
            type : 'GET',
            url : url,
            success : function(data){
                // return data; // you cannot return data here
                alert(data);  // should print [ Object ]
                try {
                    alert(JSON.stringify(data));  // should print JSON, assuming you're getting JSON
                } catch(e) {
                    alert("Error trying to parse JSON. Is your server returning JSON? " + e.message);
                }
                if(callback) callback(data);  // fire a callback function to process the data            
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                //$('#login_error').show();
                alert("error :: " + textStatus + " : " + errorThrown);
            }
        });
    }
    

    In the above code, I first created an alert so you can see if any errors are thrown. Second, I added a callback function that will fire after success is called, so that you can then process the data.

    Lastly, you will need to make sure that the URL that you are using is correct. You can use the NET tab of the Chrome or Firebug debugger to see if the request is being sent to the server when the AJAX request fires. Look for 500 errors or 404 errors or something that tells you the request was not successful. If so, check the URL to be sure that it is the same one you are using when making the GET request from your web browser’s address bar.

    What is a callback function?

    This is a function that you pass into another function as a parameter. You can then call that function and ensure it’s dynamic, meaning that you can change the behavior of your function by simply passing in different functions as a callback.

    In your case:

    doAJAXcall(url, function() { alert("I am a callback"); });
    

    Would cause this alert to be fired in your success callback, after the alerts. Functions in JavaScript are known as “first-class objects”, meaning they can be passed in by reference as parameters to another function!

    For more information on callback functions, see this link:

    https://stackoverflow.com/a/3616266/552792

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

Sidebar

Related Questions

I am trying to retrieve some data from a database using jQuery's $.getJSON method
im trying to retrieve some data using a reader in vb.net. I dont have
I am trying to retrieve some data from an API using CURL request. Is
So, I'm trying to use Doctrine to retrieve some data. I have some basic
I have some XML data retrieved from a web service that I use to
I am trying to use LINQ to retrieve some data from a dictionary. var
I'm trying to retrieve an webpage that has XML data using file_get_contents(). $get_url_report =
I have make some functions to retrieve data using the Github API. I have
I'm using Hibernate to retrieve some data from a database. The result set returned
I am trying to retrieve some rows from the database using simple SELECT statement

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.