Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning Ajax with ASP.NET
This is the forum to discuss the Wrox book Beginning Ajax with ASP.NET by Wallace B. McClure, Scott Cate, Paul Glavich, Craig Shoemaker; ISBN: 9780471785446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Ajax with ASP.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 7th, 2008, 08:46 AM
Registered User
 
Join Date: Nov 2006
Location: , , United Kingdom.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default what's wrong with my code?

OK, so I was playing around with the Try it out on pg 85, and changed the function MakeXMLHTTPCall() to include a try/catch block:

<script type="text/javascript">
        <!--
            function MakeXMLHTTPCall()
            {
                try
                {
                    var xmlHttpObj = CreateXmlHttpRequestObject()
                    if(xmlHttpObj)
                    {
                        xmlHttpObj.open("GET", "http://" + location.host + "/Javascript Playground/DataFile.xml", true);
                        xmlHttpObj.onreadystatechange = function()
                        {
                           if(xmlHttpObj.status == HTTPSTATUS_OK)
                           {
                                alert("URL exist!");
                           }
                            if(xmlHttpObj.readyState == READYSTATE_COMPLETE)
                           {
                                // Extract the response text here and place in the div element.
                                document.getElementById("divResults").childNodes[0].nodeValue=xmlHttpObj.responseText;
                           }
                        }
                    }
                    xmlHttpObj.send(null);
                 }
                 catch(Err_msg)
                    {
                        var err_msg = "Could not locate url!\n\n";
                        err_msg += "Error code: " + err_msg.description;
                        alert(err_msg);
                    }

            }


While it "sort of works" I am not getting the desired result, in firefox it loop through my

if(xmlHttpObj.status == HTTPSTATUS_OK)
{
    alert("URL exist!");
}

portion of the code with the alert showing up three times, then it loads the the data. In internet explorer It as me if I wish to debug the code. The debugger breaks on the same section of code, which indicates that the value of xmlHttpObj.status is equal to "". Which I don't quite understand. In the end if I just ignore the error in IE, it does eventually load the xml file????



Similar Threads
Thread Thread Starter Forum Replies Last Post
What's wrong with this code? appleseed C++ Programming 2 November 25th, 2006 08:17 AM
What's wrong with this code? AlDugan XSLT 3 May 19th, 2006 12:06 PM
What is wrong with code? rtr1900 Classic ASP Databases 1 April 3rd, 2006 03:20 AM
What is wrong with this code? SaharaWizard VB Databases Basics 2 January 28th, 2006 08:20 AM
what's wrong with this code? miguel.ossa ASP.NET 1.0 and 1.1 Basics 2 January 21st, 2004 11:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.