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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:04:45+00:00 2026-06-12T01:04:45+00:00

Turning off asynchronous requests in jQuery fixed the issue. I have the following Javascript

  • 0

Turning off asynchronous requests in jQuery fixed the issue.

I have the following Javascript & AJAX request (using jQuery) in my page:

    "use strict";

    var hsArea, counter, hotspots, count;
    counter = 4;
    count = 0;
    hotspots = {};

    function fetchHotspotList() {
        $.getJSON ('/alpha/engine/hotspots/gethotspot.php', {'type' : 'list'}, function(json) {
            hotspots = json;
        });
    }

    function displayHotspot(type, id, number) {
        $.ajax({
            url: '/alpha/engine/hotspots/gethotspot.php',
            dataType: 'json',
            data: {'type' : type, 'id' : id},
            success: function(json) {
                console.log(json);
                var hotspot, extract;
                    extract = json.content;
                    extract = extract.replace(/<(?:.|\n)*?>/gm, '');
                    extract = extract.substring(0, 97);
                    extract = extract + "...";
                    json.content = extract;

                    hotspot = document.createElement("div");
                    hsArea.append(hotspot);
                    hotspot.setAttribute('class','hotspot');
                    hotspot.setAttribute('id','hotspot' + number);

                    $(hotspot).css('position', 'absolute');
                    $(hotspot).css('top', number * 100 + 100);
                    $(hotspot).css('left', number * 100 + 110);

                    hotspot.innerHTML = "<h1>"+ json.title + "</h1><p>" + json.content + "</p>";
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus, errorThrown);
            }
        });
        }

        function listHotspots() {
            for(count = 0; count < counter; count++) {
                (function(count) {
                    displayHotspot('scribble',hotspots[count], count);
                    count = count + 1;  
                })(count);
            }
        }

        function loadHotspots() {
            fetchHotspotList();
            listHotspots();
        }

    $(document).ready(function() {
        hsArea = $("#hotspotArea");
        fetchHotspotList();
        listHotspots();
    });

(Sorry the formatting is a bit off!) – Now, the $(document).ready() function assigns the hsArea variable as it should, however, a combination of fetchHotspotList() and listHotspots() returns:

Uncaught TypeError: Cannot call method 'replace' of null

However, if in the Google Chrome Javascript console, I run:

loadHotspots();

it fetches the data from the AJAX request and displays it properly on the page. At first I thought the problem was that I Wasn’t using the $(document).ready() handler, but adding it hasn’t fixed it. Neither has using an onload handler inside of the body tag.

Any help would be greatly appreciated.

Regards,
Ben.

  • 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-12T01:04:46+00:00Added an answer on June 12, 2026 at 1:04 am

    It’s probably due to the fact that your listHotSpots function is called before fetchHotSpots returns (since it’s an async call).

    You’re better off chaining the execution of listHotSpots to the completion of fetchHotSpots, like so:

    function fetchHotspotList() {
        $.getJSON ('/alpha/engine/hotspots/gethotspot.php', {'type' : 'list'}, function(json) {
            hotspots = json;
            listHotSpots();
        });
    }
    

    You may be better off modifying listHotSpots to take the json data returned from your AJAX call. Hope this helps!

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

Sidebar

Related Questions

I'm looking to turn off try blocks for a specific JSP page (though turning
I am turning my PHP/MySQL/jQuery Mobile/Javascript webapp into a app thanks to Phonegap. I
I have an AJAX call with jQuery that calls a PHP script, then returns
I have a read-only database, so I am turning off ObjectTracking (thus implicitly turning
I am attempting to automation turning off connected devices to an APC PDU using
i have attempted to follow the advice at SF for turning off objective-C arc
Hello all i'm turning objects on (adding the class .active) and off on a
I'm turning a list into a set in Python, like so: request.session['vote_set'] = set(request.session['vote_set'])
In ReSharper 4.x there was a shortcut (Ctrl+8) for turning off the code analysis
I am well aware about error_reporting(0); & ini_set('display_errors', Off); to make error messages go

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.