Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

XHR only works once

This is only a duplicate question because the previous one by another developer (http://developer.appcelerator.com/question/12341/xhropen-will-only-work-once) has its comments closed.

I have a login form that accesses a web service. Upon clicking a button, it makes an XHR request to determine if the login was successful. However, if the user puts in invalid information and then tries again, the XHR request does not fired the second time. The button click fires, but the xhr.open() is never called.

I've tried recreating a new XHR object upon each button click (as suggested in the above link), but it is still not working.

— asked April 26th 2010 by Michael Szul
  • login
  • xhr
0 Comments

4 Answers

  • Accepted Answer

    Upon developing an iPad version of the iPhone application I've built, I noticed that this issue no longer seems to occur. The problem must have been fixed in a Mobile SDK update.

    — answered December 16th 2010 by Michael Szul
    permalink
    0 Comments
  • This is also happening to me but with the "share gesture", the shake is listened app wide, but when I make a XHR post request… The shake is no longer available… there could be something wrong with the XHR after all…

    — answered April 26th 2010 by Raul Riera
    permalink
    0 Comments
  • As an extremely horrible work around, I've resorted to rebuilding the window view upon a failed login attempt. This seems to reset everything. Doing it this way makes me feel dirty, so if anyone knows of a fix, please post.

    — answered April 26th 2010 by Michael Szul
    permalink
    0 Comments
  • [EDIT]!!!

    Ok, I have tracked down this issue NOT to the xhr call at all, but rather an alert dialog I was creating on failure to inform the user.
    Apparently this:

     var alertDialog = Titanium.UI.createAlertDialog({
        title: 'Login Failed',
        message: 'User not found.',
        buttonNames: ['OK']
    });
    
    alertDialog.addEventListener('click', function(e){
                alertDialog.close();
            }
    );
    

    is wrong, as that click event listener kills something in regards to my other one never being called again.

     var alertDialog = Titanium.UI.createAlertDialog({
        title: 'Login Failed',
        message: 'User not found.',
        buttonNames: ['OK']
    });
    

    That works fine, and clicking on the 'ok' button closes the dialog without issue also.

    I'll put this up as a problem as it shouldn't do anything to the other click event.

    [END EDIT]
    I'm having a similar issue. I have a button called login, it too is doing a login call using post.

    login.addEventListener('click', doLogin);
    

    First click, the method doLogin is called and all logging lines are written out, and the call happens and I get a response back. If I click the button again, not only does the call never happen, but I don't even see the log line in the console that is the first line of the doLogin function. I've tried having the

    var xhr = Titanium.Network.createHTTPClient();
    

    line be global for this page, and also within the doLogin function (so a new instance should be created each call), but neither works.

    If I take out the httpClient stuff from the doLogin function it fires as many times as I press the button.

    This is running with Android SDK, Google API v 2.2

    — answered October 15th 2010 by Simon O'Connor
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.