Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Dec 2011
    Posts
    186
    Thanks
    0
    Thanked 1 Time in 1 Post

    XMLHttpRequest Objects created in login form not talking to js in another file

    I have a simple html login form that I'll call A. A posts userid and password to a php script I'll call B.

    B contains an include() function that calls a file I'll call C.

    C has a javascript section and a php for loop that contains javascript that is sent to the browser. There are two javascript snippets outside of the for loop. One does not require an ajax object, I'll call that JS_NO. The other does. I'll call that JS_YES

    I spent a lot of time testing the javascript, and got it to work well. During the testing, the objects were always created on the same page as the rest of the javascript was written.

    I decided to put the object creating code in A. I logged in using A. JS_NO fired fine as usual. JS_YES didn't. I use firebug to see if JS_YES posted its data to its php script. Firebug showed JS_YES doing nothing at all. I used an alert to see if the JS_YES objects were created. The alert boxes told me they were.

    I moved JS_YES into file C just to see what would happen. I put it outside of the php for loop, and inside the correct script tags next to JS_NO. I logged in using A, and the javascript starting posting.

    Why didn't the XMLHttpRequest object created in A talk to the javascript in C? Why did it have to be moved into C to work?

    Thank you.
    Last edited by milesdriven; 07-22-2012 at 10:09 PM.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,473
    Thanks
    13
    Thanked 361 Times in 357 Posts
    Quote Originally Posted by milesdriven View Post
    Why didn't the XMLHttpRequest object created in A talk to the javascript in C? Why did it have to be moved into C to work?
    given that A and C are separate pages, it can be explained by JavaScript not preserving objects along different pages. (i.e. once a page is unloaded, all objects are deleted)
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Regular Coder
    Join Date
    Dec 2011
    Posts
    186
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks for your reply.

    Does that mean once I click "submit" on a login form, the javascript engine in the browser unloads (deletes) the object from the browsers memory, because the act of clicking submit moves the engine's attention away from that login form?

    If so, that would mean I always need to create an object in the same file where the javascript that uses that object is written.

    Is this right?
    Last edited by milesdriven; 07-23-2012 at 01:28 PM.

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,473
    Thanks
    13
    Thanked 361 Times in 357 Posts
    exactly. to put something new into a pot full of water you have to empty it first.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #5
    Regular Coder
    Join Date
    Dec 2011
    Posts
    186
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks

    I'm going to have to write javascript into the login form to "ask" each browser that loads this page which type of ajax object it supports.

    How do I write that javascript ( in the login form) so the response the browser gives is sent to page C in the initial example I used?

    Or do I have to write the question, and the resulting code that receives the answer and creates the object, in file C?

  • #6
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,473
    Thanks
    13
    Thanked 361 Times in 357 Posts
    Um, what I don’t understand is where the XmlHttpRequest comes into play. From what I understood, you submit the form (A), which makes AJAX pointless (in page A, at least).

    when you load page C into the browser (B is only doing stuff on the server, so it doesn’t count), then it has to load everything it needs: HTML, CSS, JavaScript.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #7
    Regular Coder
    Join Date
    Dec 2011
    Posts
    186
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Dormilich View Post
    Um, what I don’t understand is where the XmlHttpRequest comes into play. From what I understood, you submit the form (A), which makes AJAX pointless (in page A, at least).
    Part of the way I want things to work is page C sends the browser javascript that runs the moment the browser loads it. When it runs, it posts data to a entirely different php script that communicates with a database and sends a response back to the php, which sends responseText back to the javascript.

    All of this is designed to send "click the button to do this" ability to the customer, based on the real time data in several different database tables. Yes, ajax is needed to keep the customer on one page during all of this so they don't get lost on the website.

    So, in effect, I'm sending the customer ajax functionality when they log in.

    I think your telling me that any javascript that asks the logging in browser what type of object it needs to run ajax has to be written in file C too.
    Last edited by milesdriven; 07-23-2012 at 11:02 PM.

  • #8
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,473
    Thanks
    13
    Thanked 361 Times in 357 Posts
    Quote Originally Posted by milesdriven View Post
    I think your telling me that any javascript that asks the logging in browser what type of object it needs to run ajax has to be written in file C too.
    yes .
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •