| Author | Moises Lima |
| Version | 1.0 |
| License: | GPL |
| Date Added: | May 7, 2009 |
| Download URL: | Source Code (PHP 5) |
The class class.XMLHttpRequest.php is easiest way of using PHP cURL library, it's uses "XMLHttpRequest" syntax to work with cURL.
interface XMLHttpRequest
{
// Properties
readonly string error;
int maxRedirects;
readonly int readyState;
readonly string responseText;
readonly object responseXML;
readonly int status;
readonly string statusText;
// Methods
string getAllResponseHeaders();
string getResponseHeader(string label);
void open(string method, string url);
void open(string method, string url, boolean async);
void open(string method, string url, boolean async, string user);
void open(string method, string url, boolean async, string user, string password);
void send();
void send(string data);
void setRequestHeader(string label, string value);
}
A basic example of the requisition process using HTTP GET method.
<?php
require_once('class.XMLHttpRequest.php');
$ajax = new XMLHttpRequest();
$ajax->open("GET","http://www.google.com" );
$ajax->send(null);
if($ajax->status == 200){
echo $ajax->responseText;
}else echo "ERROR: $ajax->status";
?>
A basic example of the requisition process using HTTP POST method.
<?php
require_once('class.XMLHttpRequest.php');
$ajax = new XMLHttpRequest();
$ajax->open("POST","http://www.google.com/translate_t" );
$ajax->send("langpair=pt|en&text=cachorro");
if($ajax->status == 200){
echo $ajax->responseText;
}else echo "ERROR: $ajax->status";
?>
A basic example of the requisition process using HTTP TRACE method.
<?php
require_once('class.XMLHttpRequest.php');
$ajax = new XMLHttpRequest();
$ajax->open("TRACE","http://www.opera.com/" );
$ajax->send(null);
if($ajax->status == 200){
echo $ajax->getAllResponseHeaders();
echo $ajax->responseText;
}else echo "ERROR: $ajax->status";
?>
A basic example of the requisition process using HTTP HEAD method.
<?php
require_once('class.XMLHttpRequest.php');
$ajax = new XMLHttpRequest();
$ajax->open("HEAD","http://www.opera.com/" );
$ajax->send(null);
if($ajax->status == 200){
echo $ajax->getAllResponseHeaders();
}else echo "ERROR: $ajax->status";
?>
A basic example of the requisition process at XML document.
<?php
require_once('class.XMLHttpRequest.php');
$ajax = new XMLHttpRequest();
$ajax->open("GET","http://www.xml.com/2000/11/29/schemas/library1.xml" );
$ajax->send(null);
if($ajax->status == 200){
if($ajax->responseXML !=null && gettype($ajax->responseXML) == "object"){
$dom = $ajax->responseXML;
$params = $dom->getElementsByTagName('character');
echo '<table border="1"><tr><th>name</th><th>since</th><th>qualification</th></tr>';
foreach ($params as $param) {
echo '<tr><td>'.$param->getElementsByTagName('name')->item(0)->textContent.'</td><td>'
.$param->getElementsByTagName('since')->item(0)->textContent.'</td><td>'
.$param->getElementsByTagName('qualification')->item(0)->textContent.'</td></tr>';
}
echo "</table>";
}else echo "ERROR: $ajax->error";
}else echo "Status: $ajax->status ERROR: $ajax->error";
?>
Comments
Thank you!
Thank you! This is very good class!
Nice :D
Nice :D
very good!
very good!
and for php 4?
and for php 4?
Very Good class
This is very good class: Web Design
Thank you!
Thank you!
Post new comment