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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:22:27+00:00 2026-05-26T19:22:27+00:00

I am trying to write an ajax web app. I have a function that

  • 0

I am trying to write an ajax web app. I have a function that is suppose to request a json object and then use it to re/populate the website.

Here is the Javascript in Question (Lines 8 – 16):

window.onload=LoadData("Home", {});
var _doc = {};
function LoadData(page, params) {
    $.get(page, params, function ( data ) { 
        _doc = jQuery.parseJSON( data ); 
        }
    );
    document.title = _doc.Title.Title;
};

Here is the error Chrome gave:

Uncaught TypeError: Cannot read property 'Title' of undefined
LoadDatahttp://127.0.0.1/:15
(anonymous function)

This is what has me confused if I run the same statement in the console:

document.title = _doc.Title.Title;
"Home"

And it changes the title to Home

Here is proof that its not undefined:

_doc
Object
   Body: Object
      Menus: Array[4]
         0: Object
            Menu: Object
         1: Object
            Menu: Object
         2: Object
            Menu: Object
         3: Object
            Menu: Object
   Title: Object
      Title: "Home"
   User: Object
      Name: "Username"

And A screenshot as an overview:
This is What the Chrome Console Looks Like...
Note: the call to the function at the bottom did change the title

  • 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-26T19:22:28+00:00Added an answer on May 26, 2026 at 7:22 pm

    You can only access the data from the AJAX request in the callback:

    window.onload=LoadData("Home", {});
    var _doc = {};
    function LoadData(page, params) {
        $.get(page, params, function ( data ) { 
              _doc = jQuery.parseJSON( data ); 
              document.title = _doc.Title.Title;
            }
        ));
    };
    

    AJAX requests (Asynchronous JavaScript and XML) requests are asynchronous; the browser initiates the request, and does not wait for a response… instead the JavaScript execution is continued. Some time later, when the HTTP request for the AJAX request has completed, the callback you provided for the AJAX request is invoked, and has access to the data contained in the HTTP response.

    In your situation, document.title = _doc.Title.Title; is executed immediately after the AJAX request is dispatched (i.e. before the some time later mentioned above has occured); so the callback _doc = jQuery.parseJSON( data ); has not fired yet, so _doc is still an empty object, so _doc.Title is undefined, and trying to retrieve Title on the undefined _doc.Title is throwing the error.

    Unrelated to your problem, but FYI, you might want to look at the jQuery.getJSON method; the difference between that that the jQuery.get method is that the response object you get passed will already be the JSON object (so you won’t need to call jQuery.parseJSON).

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

Sidebar

Related Questions

I have been trying to write a constructor function that would make an object
I'm trying to write a web app that needs to expose some methods that
I am trying to learn how to write more dynamic web sites that use
I'm trying to write a custom servlet (for AJAX/JSON) in which I would like
im trying to write an app that will display a list off lines from
I'm trying to write a regex function that will identify and replace a single
I'm trying to make an Ajax Web Application that uses bread-crumbing to allow the
I'm trying to write a fairly complex dynamic web page, using JQuery AJAX, and
I have been trying to use an ajax-style file upload component (like the dojox
I am trying to write simple function that checks to see if a designer

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.