XMLHttpRequest on Safari
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: XMLHttpRequest on Safari

Hybrid View

  1. #1
    Join Date
    Mar 2006
    Posts
    228

    Question XMLHttpRequest on Safari

    Hello,

    I have the following JavaScript code:

    Code:
    <script language="javascript">
    var xmlhttp;
    	if (window.XMLHttpRequest) {
    		// code for IE7+, Firefox, Chrome, Opera, Safari
    		xmlhttp=new XMLHttpRequest();
    	} else if (window.ActiveXObject) {
    		// code for IE6, IE5
    		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	} else {
    		alert("Your browser does not support XMLHTTP!");
    	}
    
    	xmlhttp.open( "GET", "http://www.w3schools.com/xml/plant_catalog.xml", true );   
        xmlhttp.send(null); 
    
           xmlhttp.onreadystatechange = function () 
    	   {
    		alert( xmlhttp.responsetext );
            document.write(xmlhttp.responsetext);
    	   }
    </script>
    In Safari it comes up saying: undefined.

    does anyone know why its doing this?

    I am running Safari 5.1.2.

    Or does anyone know another way of viewing an XML/or, another page client-side, without using php or asp (server-side).

  2. #2
    Join Date
    Jun 2009
    Posts
    87

    Re: XMLHttpRequest on Safari

    You have a typo - it should be "responseText" not "responsetext", plus you need to test that there is a response and it's "OK" before you try doing anything with it:
    Code:
    xmlhttp.onreadystatechange=function()
       {
       if (xmlhttp.readyState===4 && xmlhttp.status===200)
         {
    	alert( xmlhttp.responseText );
            document.write(xmlhttp.responseText);
         }
       }
    A simple way to view XML code is using XSLT. W3Schools - as always - have a great tutorial on these: http://www.w3schools.com/xsl/default.asp

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center