p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 (http://p2p.wrox.com/forumdisplay.php?f=174)
-   -   Question on HTTP Post (http://p2p.wrox.com/showthread.php?t=51719)

dgrumbli December 19th, 2006 03:20 AM

Question on HTTP Post
 
Hi,
I just got your book “JavaScript for Web Developers”. The main reason I purchased it was to get get a better understanding of the http Requests in chapter 16. I was able to make the GET examples to work great. The POST example on page 505 (CrossBrowserHttpRequestExample2.htm) however doesn’t seem to work for me. The program runs without error but the data from the server (oRequest.responseText) is empty. I place several alert messages in the JavaScript and found that the oRequest.onreadystatechange is equal to 4, the oRequest.responseText is empty, and the oRequest.status is 405.

I have modified the sURL and verified that it is correct. I have moved this onto a development server from my local server to eliminate any issues there.

Any ideas on what I might look at next to debug this.


Thanks,
Dan

nzakas December 19th, 2006 01:48 PM

A status of 405 indicates that the method isn't allowed on the specified resource. This usually occurs if you try to send a POST request to a file type that can't do server-side logic, such as a plain text file. Try posting to a PHP file (I'm not sure, but it may even work with a regular HTML file) and it should work fine.

Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/

dgrumbli December 20th, 2006 01:18 AM

Thanks, the PHP file was the problem, I replaced it with and asp file and it now works for IE but I still have a problem with Netscape.

Using Netscape, I make it to onreadystatechange function. The program starts to execute the onreadystatechange and then terminates. To look at this I placed a couple of alert statements in the code. By monitoring the oRequest.readyState I see that in IE I get an alert for 2, 3, and then 4 which then continues to completion of the program. In Netscape I get a 1, then a 2 and the program terminates.

Any ideas what may be wrong with Netscape? I have included the onreadystatechange code below I am monitoring.

        oRequest.onreadystatechange = function () {
            if (oRequest.readyState == 4) {
            alert(oRequest.readyState + ":" + oRequest.responseText + ":" + oRequest.status );

                fnCallback(oRequest.responseText);
            }
        alert(oRequest.readyState);
        }


Thanks,
Dan

nzakas December 20th, 2006 02:03 PM

Sorry, I haven't used Netscape in a very long time, so I'm not sure why it specifically would have a problem. The most likely issue is some kind of error. You should check the status property for a better indication of what might possibly be wrong.

Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/


All times are GMT -4. The time now is 05:57 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.