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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:15:18+00:00 2026-05-23T23:15:18+00:00

I have an Ajax function which looks like : function getData(p) { loadingImage(); p

  • 0

I have an Ajax function which looks like :

  function getData(p) {
  loadingImage();
  p = p.replace("frame_", "");
  if (window.XMLHttpRequest) {              
    AJAX=new XMLHttpRequest();              
  } else {                                  
    AJAX=new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (AJAX) {
     var __page =encodeURIComponent(p);
     AJAX.open("GET", "page.php?page="+__page, false);                             
     AJAX.send(null);
     var __data = AJAX.responseText.match(/<data>[\s\S]*?<\/data>/gmi);
     if(!__data) { return false; }
     return __data;      
  } else {
     return false;
  }      
}

then i have very simple loading function ( an loading image must appear in center of page ) :

function loadingImage(type)
{
   document.getElementById("body").innerHTML = "<div class='loading'></div>";
}

then how i call ajax function :

 var loadedData = getData("home");
 if(loadedData)
 {
   document.getElementById("body").innerHTML = loadedData;
 }
 else
 {
  document.getElementById("body").innerHTML = "Error";
 }

but the loading image won’t appear, it’s quite simple, but i’m stuck here , how make it to show that loading image while requesting data, then to replace loading image with loaded data. Thanks

  • 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-23T23:15:20+00:00Added an answer on May 23, 2026 at 11:15 pm
    function getData(p, cb) {
        loadingImage();
        p = p.replace("frame_", "");
        if (window.XMLHttpRequest) {
            AJAX = new XMLHttpRequest();
        } else {
            AJAX = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if (AJAX) {
            var __page = encodeURIComponent(p);
            AJAX.open("GET", "page.php?page=" + __page, true);
            AJAX.onreadystatechange = function(e) {
                if (AJAX.readystate === 4) {
                    var __data = AJAX.responseText.match(/<data>[\s\S]*?<\/data>/gmi);
                    cb(data);
                }
            };
            AJAX.send(null);
        } else {
            cb(null);
        }
    }
    
    getData("home", function(loadedData) {
        if (loadedData) {
            document.getElementById("body").innerHTML = loadedData;
        }
        else {
            document.getElementById("body").innerHTML = "Error";
        }
    });
    

    Use async = true in the .open call.

    Bind an eventhandler to readystatechange. If the readystate is 4 (LOADED) then get the data and send it to your callback.

    If the AJAX fails call the callback with null or false.

    In your callback get the loadedData and either render it or throw an error if there is no data.

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

Sidebar

Related Questions

I have an an ajax request that looks like this, $('input.fakecheck').click(function(){ alert(deleteing....); $.ajax({ url:/search,
I have my own edit in place function for jquery which looks like this
I have written a simple jQuery.ajax function which loads a user control from the
I have some content from server using $.ajax() function. I try to replace some
Here's an interesting problem: I have some jQuery that looks like this: $(document).ready(function() {
I have a jQuery ajax call that looks like this: $.ajax({ type : 'GET',
I have a AJAX requests which returns a string of XML which I'd like
I have a list which looks like the following: <ul id=offers> <li class=unique-id-here> <span
I have some jQuery that looks like this: $.ajax({ type: POST, url: /Customer/CancelSubscription/<%= Model.Customer.Id
I have a function which loads up relevant js functions on click using ajax's

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.