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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.