/* CHTTPQ (C/W) CI:A - Certus In Audio [http://certus.in/] */ /-= CHTTPQ =--------------------------------------------------------------- | | ABOUT | | This class implements a simple Javascript HTTP query library. | This allows to make (HTTP and HTTPS) requests, exchange data | with a server, and modify the current page without reloading | it, on an easy way through Javascript. Submitting forms and | retrieving additional content are two common uses. All modern | browsers support the XMLHttpRequest object (IE5 and IE6 use an | ActiveXObject), which is the base object used in this class. | | ATTRIBUTES/FIELDS | | {private} object _self | {public} string strDebugMessagesContainer | {public} integer intState | {public} integer intStatus | {public} array arrHeaders | {public} string strText | {private} string _strURL | {private} array _arrParameters | {private} boolean _bEscapeParameters | {private} boolean _bUsePostRequests | {private} string _strPostDataContentType | {private} string _strCallbackFunction | {private} object _objHTTP | | METHODS | | {private} boolean _isValidBoolean( boolean ) | {private} boolean _isValidString( string ) | {private} boolean _isValidURL( string ) | {private} boolean _doDM( string ) | {public} boolean setURL( string ) | {public} string getURL( void ) | {public} boolean checkURL( void ) | {public} boolean addParameter( string , string ) | {public} boolean setParameter( string , string ) | {public} boolean deleteParameter( string ) | {public} boolean hasParameter( string ) | {public} array listParameters( void ) | {public} integer countParameters( void ) | {public} string getParameter( string ) | {public} boolean setEscapeParameters( boolean ) | {public} boolean getEscapeParameters( void ) | {public} boolean setUsePostRequests( boolean ) | {public} boolean getUsePostRequests( void ) | {public} boolean setPostDataContentType( string ) | {public} string getPostDataContentType( void ) | {public} boolean setCallbackFunction( string ) | {public} string getCallbackFunction( void ) | {public} boolean doQuery( void ) | | USAGE | | First of all, including this class file would be a good idea. | The easiest way to do this is to place the following code into | the HEAD-section of a HTML document: | | | The next step is to create an object instance of type CHTTPQ, like: | objQ = new CHTTPQ(); | | After doing this, there are only two tasks left, in fact; these | are: set up an URL for a request and define a response-handler- | function. This function will be called after receiving a response | from a server. Note: this can be several times. The CHTTPQ class | serves four public fields (variables), which allows to determine | the current state of a query, HTTP status, HTTP headers and response | text. These variables are: | - intState .... : 1=open , 2=sent , 3=receiving , 4=loaded | - intStatus ... : HTTP status code | - arrHeaders .. : HTTP headers | - strText ..... : response text | | The following lines demonstrate how to define and implement a | response-handler-function: | function handleResponse() { document.status = objQ.intState; } | objQ.setCallbackFunction( "handleResponse" ); | | Set up an URL for a request and do a query; example: | objQ.setURL( document.location.toString() ); | objQ.doQuery(); | | EXAMPLE | | | | Example | | | | | | | | \-------------------------------------------------------------------------- 0 ) { header( "Content-Type: text/plain" ); echo "Parameter send method = " . ( ( count( $_GET ) > 0 ) ? "GET" : "POST" ) . "\n" . str_ireplace( "array" , "Parameters:" , print_r( $_REQUEST , true ) ); exit; } ?> CHTTPQ Demo
CHTTPQ Demo