[SOLVED ]Ajax Test

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

[SOLVED ]Ajax Test

Post by phpcoder »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,
Its me trouble again 

This is code I am using for testing:

script.js
[syntax="javascript"]
function getQuery() 
	{
        	var xmlHttp=null;
        	try {
                	// Firefox, Opera 8.0+, Safari
                	xmlHttp=new XMLHttpRequest();
        	} 
		catch (e) 
		{
                // Internet Explorer
                try {
                        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                	}	
		 catch (e)
		 {
                  try {
                           xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                      } 
			catch (e) {
                                alert ("Your browser does not support AJAX and this page will not function correctly.");
                                return;
                        }
                }
        }

        if (xmlHttp===null) {
                alert ("Your browser does not support AJAX and this page will not function correctly.");
                return;
        }
        xmlHttp.overrideMimeType("text/html");
        var url="http://localhost/checkSession.php";
        xmlHttp.open('GET',url,true);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange=function() {
                if (xmlHttp.readyState==4) {
                        document.getElementById("txtHere").innerHTML=xmlHttp.responseText;
                }
        }
        xmlHttp.send(null);
}
chechSession.php[/syntax]

Code: Select all

<?php
	session_start();
	$_SESSION['item'] = "CKone";
	
?>
ajaxTest.php

Code: Select all

<?php
	session_start();
	$_SESSION['item'] = "D&G";
	
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
        <head>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                <title>AJAX Fun!</title>
                <script type="text/javascript" src="script.js" />
        </head>
        <body>
                <p>AJAX Test...</p>
                <p>Make a selection below to do things.</p>
                <a href="javascript:getQuery()">Query 1</a>
                
                <div id="txtHere">This will change when you select something</div>
        </body>
</html>
	

<?php
echo "Now the session is";
echo $_SESSION['item'];
?>
If I want to return some thing from chechSession.php and want to display the returned value on the ajaxTest.php please show me how can I do it.
thanks


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by phpcoder on Wed Jul 04, 2007 4:15 am, edited 1 time in total.
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

chechSession.php

Code: Select all

<?php
        session_start();
        $_SESSION['item'] = "CKone";

        echo "hello world!";
?>
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

djot wrote:chechSession.php

Code: Select all

<?php
        session_start();
        $_SESSION['item'] = "CKone";

        echo "hello world!";
?>
Sorted Thanks
Post Reply