Ajax and php : XMLHttpRequest « Ajax Layer « JavaScript DHTML

Home
JavaScript DHTML
1.Ajax Layer
2.Data Type
3.Date Time
4.Development
5.Document
6.Dojo toolkit
7.Event
8.Event onMethod
9.Ext JS
10.Form Control
11.GUI Components
12.HTML
13.Javascript Collections
14.Javascript Objects
15.Javascript Properties
16.jQuery
17.Language Basics
18.Mochkit
19.Mootools
20.Node Operation
21.Object Oriented
22.Page Components
23.Rico
24.Scriptaculous
25.Security
26.SmartClient
27.Style Layout
28.Table
29.Utilities
30.Window Browser
31.YUI Library
JavaScript DHTML » Ajax Layer » XMLHttpRequest 




Ajax and php
 
<html>
<head>
<title></title>
</head>
<body>
<div id="xmldata"></div>
<script type="text/javascript">
function readyAJAX() {
try {
    return new XMLHttpRequest();
catch(e) {
    try {
        return new ActiveXObject('Msxml2.XMLHTTP');
    catch(e) {
        try {
            return new ActiveXObject('Microsoft.XMLHTTP');
        catch(e) {
            return "A newer browser is needed.";
        }
    }
}
}
var requestObj = readyAJAX();
var url ="http://127.0.0.1/sum.php?num1=2&num2=2";
requestObj.open("GET",url,true);
requestObj.send();
requestObj.onreadystatechange = function() {
    if (requestObj.readyState == 4) {
        if (requestObj.status == 200) {
            document.write(requestObj.responseText);
        else {
            document.write(requestObj.statusText);
        }
    }
}
</script>
</body>
</html>


//sum.php

<?php
print $_GET['num1'] + $_GET['num2'];
?>

   
  














Related examples in the same category
1.Is your Browser Ajax ready
2.Use XMLHttpRequest to send and read data
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.