Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Ajax issue, problems with the responseXML from an XMLHttpRequest: (10 Items)
   
Ajax issue, problems with the responseXML from an XMLHttpRequest  
Has anybody attempted to use the responseXML variable from XMLHttpRequest?

I am successfully using slinger and cgi to return ajax data with the XMLHttpRequest object.  However I can not seem to 
get the responseXML to parse through my xml stream?

I believe it has something to do with the browser not interpreting the header type "Content-Type: text/xml".

I am close to abandoning the responseXML variable and parsing the xml stream returned in the response variable manually.
 

Hopefully somebody else out there has dealt with this.

Thanks.

Re: Ajax issue, problems with the responseXML from an XMLHttpRequest  
I had that issue also.  Windows flashplayer does not require anything before the xml document but qnx flashplayer does!

I send...

"HTTP/1.1 200 OK Server: custom-cgi Connection: close \r\nContent-Type: text/html\r\n\r\n"

followed by a valid xml document.  Then it works fine.  

I was using openLaszlo not AJAX.
Re: Ajax issue, problems with the responseXML from an XMLHttpRequest  
I think I a missing something fundamental.  I am new to AJAX and I am having difficulty understanding exactly what needs
 to be sent back from the server wrt headers and meta data.

Is it possible to get the complete text stream that is returned from the server?

Thanks for the help.
Re: Ajax issue, problems with the responseXML from an XMLHttpRequest  
Remember this works for openLaszlo - I haven't used Ajax - but the underlying actionscript is the same.  I use <lf> line
 endings (except as posted above in the header).

Stream can be as minimal as...

HTTP/1.1 200 OK Server: custom-cgi Connection: close 
Content-Type: text/html

<?xml version=\"1.0\"?>
<status>
 <status1>OK</status1>
</status>


Longer stream...

HTTP/1.1 200 OK Server: custom-cgi Connection: close 
Content-Type: text/html

<?xml version="1.0" ?>
<thermodynData>
    <inputs>
        <ts_mode>HEAT</ts_mode>
        <ts_fan>AUTO</ts_fan>
        <ts_temp>72</ts_temp>
    </inputs>
    <outputs>
        <td_temp_in>72</td_temp_in>
        <td_temp_out>60</td_temp_out>
        <td_sys>OFF</td_sys>
        <td_time>04:50p</td_time>
    </outputs>
    <parameters>
        <pm_interval>200</pm_interval>
        <pm_minutes>2</pm_minutes>
    </parameters>
</thermodynData>

Re: Ajax issue, problems with the responseXML from an XMLHttpRequest  
My gut says I am still not getting the header to transfer correctly?

In the documentation for slinger it states:

When Slinger executes a CGI script, it parses the output of the script for HTTP header directives. Slinger must buffer 
the header directives, before transmitting the script data, in case a header directive is passed that'll affect the 
format of the default header directives. Up to 1K of header information can be buffered. CGI scripts must provide a 
valid header.

Slinger identifies the end of the header as a blank line, lines are terminated with a <LF> or a <CR><LF>. A common HTTP 
header directive to provide specifies the type of data that the CGI script provides. The default Content-Type is "text/
html." For example:

   Content-Type: text/html<LF>
   <LF>
   CGI script data...

However, it does not seem to be capturing any of my stream as a header?  For example, I tried changing the status return
 to 201, but it does not have any effect on the actual status which the XMLHttpRequest object gets.

When I look at the page source for the return I see:

HTTP/1.1 Status: 201 OK Server: custom-cgi Connection: close 
Content-Type: text/xml<LF><LF>
<?xml version="1.0"?><quad-1>
<Q1-State>Charge</Q1-State>
<Q1-SubState>Charging</Q1-SubState>
</quad-1>


My XMLHttpRequest object is requesting the page xml_data.shtml from slinger.  The contents of xml_data.shtml is simply:

<!--#config cmdecho="ON" -->
<!--#exec cmd="/usr/web/cgi/TFWeb 1" -->

The cmd line output from "TFWeb 1" is:

HTTP/1.1 Status: 201 OK Server: custom-cgi Connection: close
Content-Type: text/xml<LF>
<LF>
<?xml version="1.0"?>

<quad-1>
<Q1-State>Charge</Q1-State>
<Q1-SubState>Charging</Q1-SubState>
</quad-1>

I also tried moving the header data into the shtml file instead of as output from the executable with no affect.

Any ideas?  And again thanks.
Re: Ajax issue, problems with the responseXML from an XMLHttpRequest  
The only thing I see is...

Content-Type: text/html
vs
Content-Type: text/xml
Re: Ajax issue, problems with the responseXML from an XMLHttpRequest  
From my readings on the web, it is one of the requirements for the responseXML variable to be filled.

Otherwise, I get NULL.

Either way, thanks for the input.  At least you have confirmed that my process is reasonable.

I'll play with this at home over the weekend using apache and PHP to see if I can get it working and maybe learn some 
something applicable to the QNX word.

RE: Ajax issue, problems with the responseXML from an XMLHttpRequest  
Doesn't look like a valid HTTP response to me.  I believe the spec
(http://www.w3.org/Protocols/rfc2616/rfc2616.html) says everything is
terminated by a <CR><LF> pair which seem to be missing here:

> HTTP/1.1 Status: 201 OK Server: custom-cgi Connection: close
> Content-Type: text/xml<LF><LF>
> <?xml version="1.0"?><quad-1>
> <Q1-State>Charge</Q1-State>
> <Q1-SubState>Charging</Q1-SubState>
> </quad-1>

I would imagine you want to have:

HTTP/1.1 Status: 201 OK<CR><LF>
Server: custom-cgi<CR<LF>
Connection: close<CR<LF>
Content-Type: text/xml<CR><LF><CR><LF>
<?xml version="1.0"?><quad-1>
<Q1-State>Charge</Q1-State>
<Q1-SubState>Charging</Q1-SubState>
</quad-1>
Re: RE: Ajax issue, problems with the responseXML from an XMLHttpRequest  
No impact.  Thanks though.
Re: Ajax issue, problems with the responseXML from an XMLHttpRequest  
Using the intermediate SSI file with the command:
 <!--#config cmdecho="ON" -->
 <!--#exec cmd="/usr/web/cgi/file.cgi" -->

Was causing the problem.

I requested directly from the cgi file using cgi-bin/file.cgi as the url and slinger correctly parsed the header 
information.

Once the header was being parsed I can control the settings and successfully fill the responseXML with a valid DOM.

Greg