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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:33:51+00:00 2026-06-14T13:33:51+00:00

After a long research here, I tried to handle some AJAX data via callback.

  • 0

After a long research here, I tried to handle some AJAX data via callback. I’m an italian user, so I apologize if I’ll not be clear with my explanation (actually, it’s pretty difficult for me to explain my problem in english).

I’m trying to pass some data via callback. My jQuery.ajax.async is not set on false, because I need to work in asynchronous mode. So I’m trying to pass a callback to my function, according to some posts I found here. But if I try to show this data via alert function, I can see it’s undefined. Here’s the code:

function loadentities(id, username, password, system, host)
{
    var postData = "username=" + encodeURI(username) +
        "&password=" + encodeURI(password) +
        "&system=" + encodeURI(system) +
        "&host=" + encodeURI(host);

    jQuery.ajax({

        type: "POST",
        dataType: "json",
        data: postData,
        beforeSend: function(x) 
        {       
            if(x && x.overrideMimeType) 
            {   
                x.overrideMimeType("application/json;charset=UTF-8");
            }
        },
        url: 'operations.php?op=loadentities',
        error: function(x, textStatus, errorThrown)
        {
            alert("Request failed: " + textStatus + " " + errorThrown);
        },
        success: function(data) 
        {
            var html = "";
            for(var i=0; i < data.length; i++)
            {
                html += "<li><a onclick=\"showhide('" + data[i].entity + "');\">" + data[i].entity + "</a><ul id=\"" + data[i].entity + "\" class=\"list\"></ul></li>"; 
                loadlastfiveevents(username, password, system, host, data[i].entity, function(data)
                            {
                                 alert(data);
                                 entityData = new Array(); 
                                 for(var i = 0; i < data.length; i++)
                                 {
                                     var entityDataEntry = new Object();
                                     entityDataEntry.key = data[i].key;
                                     entityDataEntry.event = data[i].event;
                                     entityDataEntry.timestamp = data[i].timestamp;
                                     entityData.push(entityDataEntry);
                                 }
                                 alert(data[0].key);                                                      
                             });
                entitiesValues[entitiesIndex++] = data[i].entity;
            }

            jQuery(html).appendTo('#hlentity' + id);
        }
    }); //end jQuery.ajax
}

function loadlastfiveevents(username, password, system, host, entity, buildlastfiveevents)
{
    var postData = "username=" + encodeURI(username) +
        "&password=" + encodeURI(password) +
        "&system=" + encodeURI(system) +
        "&host=" + encodeURI(host) +
        "&entity=" + encodeURI(entity);

    jQuery.ajax({

        type: "POST",
        dataType: "json",
        data: postData,
        beforeSend: function(x) 
        {       
            if(x && x.overrideMimeType) 
            {   
                x.overrideMimeType("application/json;charset=UTF-8");
            }
        },
        url: 'operations.php?op=getlatestevents',
        error: function(x, textStatus, errorThrown)
        {
            alert("Request failed: " + textStatus + " " + errorThrown);
        },
        success: function(data) 
        {
            var color = "green";
            var html = "";
            for(var i = 0; i < data.length; i++)
            {
                if(data[i].event == "SUP") color = "green";
                else if(data[i].event == "IER") color = "yellow";
                else if(data[i].event == "SDW") color = "black";
                else color = "red";
                html += "<li><img src=\"images/" + color + ".jpg\" />" + data[i].key + " " + data[i].event + " " + data[i].timestamp + "</li>"; 
            }
            jQuery(html).appendTo('#' + entity);
            propagate(entity, data[0].event);
            buildlastfiveelements(data);
        }
    }); //end jQuery
}

I hope this post is clear enough, thank you for your patience and time.

EDIT: here’s a sample of the JSON code returned by getlatestevents (within loadlastfiveevents).

[
    {
        "key": "error",
        "event": "SUP",
        "timestamp": "2012-11-16 11:13:36"
    },
    {
        "key": "error",
        "event": "SDW",
        "timestamp": "2012-11-16 11:12:57"
    },
    {
        "key": "error",
        "event": "SUP",
        "timestamp": "2012-11-16 11:11:32"
    },
    {
        "key": "error",
        "event": "SDW",
        "timestamp": "2012-11-15 19:40:31"
    },
    {
        "key": "timeout",
        "event": "SER",
        "timestamp": "2012-11-15 19:30:54"
    }
]
  • 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-14T13:33:52+00:00Added an answer on June 14, 2026 at 1:33 pm

    This won’t work.

    You’re setting the datatype to json, meaning you expect a JSON result to be returned, anything else will fail.

    Then you use a for loop iterating based on the returned JSON objects length, and since objects don’t have a length the for loop never runs.

    You’re either expecting arrays, which have a length property, but they are not coming thru since the datatype is set to JSON, or you’re expecting objects, which are coming thru as JSON objects, which don’t have a length property and must be looped with for(key in object) or $.each(object, function(key, value) {...}) etc..

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

Sidebar

Related Questions

After a long research here on Stackoverflow and on net I didn't found nothing
After a long search I'm still confused about it although I found some related
First of all i am a n00b. After long time of trying and research
After long searches, I succeed to delete a row in a jqgrid with form
After a long time searching and trying I'm asking now for help: My situation:
After a long investigation on how to use TFS 2010 I started with the
How long after a document is fed to the Google Search Appliance using a
I am returning to C++ after a long absence and I am stumbling a
I'm currently re-engaging with Python after a long absence and loving it. However, I
I'm getting back in to Cocoa development on the Mac after a long stint

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.