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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:12:02+00:00 2026-05-23T00:12:02+00:00

Q.js file Q = {}; Q.stringFile = []; Q.file = CSS.txt; Q.getData = function(Q.file){

  • 0

Q.js file

Q = {};

Q.stringFile = [];
Q.file = "CSS.txt";

Q.getData = function(Q.file){
    $.get(Q.file, function(data){
        var str = data;
        Q.stringFile = str.split("\n"); 

        return Q.stringFile;
    });
}

a.html file

<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>   
    <script type="text/javascript" src="Q.js"></script>
    <script type="text/javascript">
        var d = Q.getData(Q.file);
        alert(d);
     </script>

</head>

<body>

</body>
</html>

alert doesn’t output!

Errors: Q is not defined ;
unexpected token .

How do i fix this??

  • 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-23T00:12:03+00:00Added an answer on May 23, 2026 at 12:12 am

    As I said in my comment, you cannot return data from an Ajax call, as the Ajax call is asynchronous. You have to make your function accept a callback, like:

    Q.getData = function(file, callback){
        $.get(file, function(data){
            var stringFile = data.split("\n"); 
            callback(stringFile);
        });
    };
    

    and then call it with:

    Q.getData(Q.file, function(d) {
        alert(d);
    });
    

    Regarding the errors: You have a syntax error in this line

    Q.getData = function(Q.file)
    

    Q.file is not valid here. The browser cannot parse and process the file and so Q will not be defined.


    I have the impression, you should first read some tutorial before you go on.

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

Sidebar

Related Questions

I have a C# application that includes the following code: string file = relativePath.txt;
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Upload(Photo photo) { foreach (string file in Request.Files) { var path
I am attempting to get a directory (which is ever-growing) full of .txt comma
I have the following method GetData that creates a StreamReader from a file. private
I am trying to load the html content using c# (To simulate php function
I have a project where I get a list of file location strings that
If I change myfile(input.txt) to myfile(file_name)...where file_name is passed to the function it does
I have a txt file that contains name, id number, mobilenumber, and location in
Given a string file path such as /foo/fizzbuzz.bar , how would I use bash
Perl is really good for writing the kind of string/file parsing programs that I

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.