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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:04:39+00:00 2026-06-05T02:04:39+00:00

I’m just learning JavaScript Objects and have a question/problem. I have the following code

  • 0

I’m just learning JavaScript Objects and have a question/problem. I have the following code / js object:

CHANGED: This is the complete code – it’s a Appcelerator Titanium Project!:

spike.xhr = spike.xhr || {};

spike.xhr.init = function() {
    this.severResponse = '';
    this.xhrMethod = 'GET';
}

spike.xhr.isOnline = function() {
    if( Titanium.Network.online ) {
        return true;
    } else {
        return false;
    }
}

spike.xhr.notOnline = function() {
    var alertDialog = Titanium.UI.createAlertDialog({ 
        title: CONFIG.PROJECT_SHORT, 
        message: 'You do not have an online connect. Please connect...',
        buttonNames: ['Continue'],
        cancel: 0
    }); 
    alertDialog.show(); 
}

spike.xhr.connect = function( url ) {

    if( spike.xhr.isOnline() ) {
        spike.xhr.clients = Ti.Network.createHTTPClient();

        spike.xhr.clients.onload = function() {
            if (spike.xhr.clients.status != 200 && spike.xhr.clients.status != 201) {
                var alertDialog = Titanium.UI.createAlertDialog({ 
                    title: CONFIG.PROJECT_SHORT, 
                    message: 'We are sorry, but we have received an status error!',
                    buttonNames: ['Continue'],
                    cancel: 0
                }); 
                alertDialog.show(); 
                return false;
            }    
            this.serverResponse = this.responseText; 
        }

        spike.xhr.clients.onerror = function(e) {
            Ti.API.log( 'ERROR: ' + e.status + ': ' + e.statusText + ' - ' + e.error );
        }   

        spike.xhr.clients.open( this.xhrMethod, url );

        spike.xhr.clients.send();
    } else {
        spike.xhr.notOnline();
    }
}

spike.xhr.basicAuthentication = function( username, password ) {
    authstr = 'Basic ' +Titanium.Utils.base64encode( username+':'+ password);
    spike.xhr.client.setRequestHeader( 'Authorization', authstr );
}

spike.xhr.setMethod = function( type ) {
    this.xhrMethod = type;
}

spike.xhr.response = function() {
    return this.serverResponse;
}

If I now run:

spike.xhr.connect( 'http://mydomain' );
theResponse = spike.xhr.response();

I get <null> returned! – why do I not get "This is a Test!" back or better question:
What do I have to change to get "This is a Test!" back?

  • 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-05T02:04:40+00:00Added an answer on June 5, 2026 at 2:04 am

    The reason the above code doesn’t work is because your spike.xhr.connect function is asynchronous. This means you can tell the browser to make a request, but continue doing other stuff while the browser waits for the response to come back.

    JavaScript runs in a single thread, meaning that you can only execute one thing at a time. Certain operations like “AJAX” calls are asynchronous in that the browser knows how to make that request, but doesn’t block your currently running code to wait for the request. Typically, asynchronous code is called with a callback function, which runs when the request is returned:

    // pseudo code.
    
    spike.xhr.connect( 'http://google.com', function ( response ) {
        alert( 'google' );
    });
    alert( 'this will fire before spike.xhr.connects callback' );
    

    The callback function will be executed when the response from the server comes back AND the browser isn’t doing anything else.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) 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.