Jump to content

Ajax Basics


Drezard

Recommended Posts

Trying to get some basic PHP and ajax up and running. Here is my first example:

 

<?php

session_start();

?>

<html>

<head>

    </head>
    
  	<body>
    
    	<script type="text/javascript">

		var xmlhttp = false;

		try 
		{

			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

			alert("You are using Microsoft Internet Explorer");

		}

		catch (e) 
		{

			try 
			{

			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

			alert("You are using Microsoft Internet Explorer");

			catch(E) 
			{

				xmlhttp = false;

				alert("You are not using Microsoft Internet Explorer");		

			}

		}

	</script>
    
    </body>
    
</html>

 

This just provides a blank white page.

 

Whats wrong?

 

Daniel

Link to comment
https://forums.phpfreaks.com/topic/117512-ajax-basics/
Share on other sites

you were missing a close brace before the second CATCH:

 

<?php
session_start();
?>
<html>
  <head>
    </head>
    <body>
      <script type="text/javascript">
      var xmlhttp = false;
      try 
      {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        alert("You are using Microsoft Internet Explorer");
      }
      catch (e) 
      {
        try 
        {
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          alert("You are using Microsoft Internet Explorer");
        }
        catch(E) 
        {
          xmlhttp = false;
          alert("You are not using Microsoft Internet Explorer");   
        }
      }
    </script>
    </body>
</html>

 

if you are REALLY interested in learning exactly how the XMLHTTP object works, feel free to keep going down this road. But if you are more interested in what you can DO with AJAX, I would recommend using a JavaScript library. The popular ones are jQuery, Prototype, and MooTools. They have easy functions that make AJAX cross-browser friendly.

Link to comment
https://forums.phpfreaks.com/topic/117512-ajax-basics/#findComment-604506
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.