www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] Series of HTTP Requests/Responses Not Divided Properly: PHP or Ajax control?

  1. #1
    Join Date
    Jul 2010
    Posts
    66

    resolved [RESOLVED] Series of HTTP Requests/Responses Not Divided Properly: PHP or Ajax control?

    This problem I have could come from the server or client side, so since I am using PHP, I will put it here. (If I don't get an answer, I will post to Javascript/Ajax forum.)

    According to Firebug (Net tab) I am not getting proper division between my HTTP requests and responses using Ajax.

    All my requests and responses are validated XML markup on both sides.

    I have the user click a Login button, and a series of three HTTP requests and responses are started. The first is a login, the second is to request a list of users, and the third a request a lists of tests. The abbreviated XML is shown below for the request and responses of just the login (authorization) and user listing requests and responses.

    These requests and responses are not divided by a pause for a user action, like a form control action (button click).

    The authorization request goes out via an Ajax POST method, and the authorization response comes back. Then the userlisting request goes out, again by Ajax POST method (it will always be the way) and userlisting response comes back.

    The PROBLEM: I see two HTTP Request/Response POST actions in Firebug Net tab.

    The second HTTP Request/Response (userlisting) seems OK. The client has parsed the XML (in responseXML property) and it is the userlisting response.

    But the first HTTP Request/Response does NOT show valid parsed XML, and the reason is clear: it has as text in the response BOTH the XML response of the authorization and the userlisting one after the other. This means that the client is not "closing" the HTTP response in the first case. I do not why the userlisting is "repeated" in valid form in the second HTTP Request/Response.

    The QUESTION: Is there something in PHP I should be sending in the output to the client to tell it to "close" the HTTP response so there is proper division by Ajax control on the client side?

    HTML Code:
       <!-- Request #1: authorization -->
       <!-- XML prolog, including
         declaration: <?xml version .... ?>
         standalone DTD:  <![DOCTYPE ... ]]> -->
       <request type="authorization" ... >
        <!-- contained elements -->
       </request> 
    
       <!-- Response #1: authorization -->
       <!-- XML prolog, including
         declaration: <?xml version .... ?>
         standalone DTD:  <![DOCTYPE ... ]]> -->
       <response type="authorization" status="ok" ...>
        <!-- contained elements -->
       </response>
    
    
       <!-- Request #2: user listing -->
       <!-- XML prolog, including
         declaration: <?xml version .... ?>
         standalone DTD:  <![DOCTYPE ... ]]> -->
       <request type="listing" ctype="users" ... >
        <!-- contained elements -->
       </request> 
    
       <!-- Response #2: user listing -->
       <!-- XML prolog, including
         declaration: <?xml version .... ?>
         standalone DTD:  <![DOCTYPE ... ]]> -->
       <response type="listing" ctype="users" ... >
        <userlist>
         <user id="">
         ...
         </user>
         ...
        <!-- contained elements -->
       </response> 

  2. #2
    Join Date
    Jul 2010
    Posts
    66

    Necessary to Create New Ajax Request Objects for Each New Request

    Okay, I am answering my own thread/question.

    The ANSWER: Upon further reading, namely S. Holzner's Ajax Bible, specifically Chap 4. "Serious Ajax Programming," I learned that my problem was re-using the Ajax request object. Thus it is NOT a PHP problem, but an Ajax/Javascript problem.

    I was sending synchronous requests in this series, so did not expect that to be trouble. But it apparently is. I followed the advice in the book, namely by constructing new Ajax request objects for each separate request, and the problem went away.

    Until the next problem...
    Last edited by seniseven; 11-14-2012 at 12:12 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles