// Credit: http://www-128.ibm.com/developerworks/xml/library/x-ajaxxml3/index.html?ca=dnw-812
function ajx_process_reqChange() {
if (req.readyState == 4){
if(req.status!=200){
if(typeof(onfailure)=='function'){
onfailure();
}
}
else{
if(typeof(onsuccess)=='function'){
onsuccess();
}
}
}
}
function js_ajax_load_url( url, successCallback, failureCallback){
if(window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
}
catch(e) {
req = false;
}
}
else if(window.ActiveXObject) {
try {
req = new ActiveXObject('Msxml2.XMLHTTP');
}
catch(e) {
try {
req = new ActiveXObject('Microsoft.XMLHTTP');
}
catch(e) {
req = false;
}
}
}
if(req) {
onfailure = failureCallback;
onsuccess = successCallback;
req.onreadystatechange = ajx_process_reqChange;
req.open('GET', url, true);
req.send('');
}
}
var req = null;
var onfailure = null;
var onsuccess = null
req = null;
//-------------------------------------------------------------------------
// Example:
[html]
[head]
[script language="Javascript" src="js_ajax.js"][/script]
[script language="Javascript"]
function onsuccessCallback(){
alert(req.responseText);
}
function onfailureCallback(){
alert('failed');
}
window.onload = registerEvents;
function registerEvents(e){
js_ajax_load_url('test.php', onsuccessCallback, onfailureCallback)
}
[/script]
[/head]
[body]
[/body]
[/html]
PHP and javascript snippets you can copy and paste.
Saturday, April 14, 2007
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2007
(71)
-
▼
April
(24)
- js_map_keyPress(actualKeyPress,keyPressToMatch,cal...
- js_get_keyCode(e)
- js_create_socialBookmarks(container,path_to_icons)
- js_ajax.js
- net_upload_photosToFlickr($yourFlickrEmailAddress,...
- js_is_image(ext)
- js_php_parse_url(url)
- file_do_download($fileName)
- xml_replace_nodeContent( &$node, &$new_content )
- arr_add_elementToStart($a,$el)
- fnc_call($funcName)
- sec_quote_SQLStr($sql)
- net_convert_arrayToUrlStr($arr)
- xml_get_nodeChildren($xpathObj,$path,$index=0)
- xml_get_XMLStrFromXPath($xpathObj,$path,$index=0)
- xml_remove_elementsByTagName($parentNode,$tagName)
- xml_append_childNode($parentNode,$childNode)
- xml_create_elementWithText($doc, $name, $value)
- xml_clone_xpathToNewDOM($origXPath,$path)
- xml_create_node($xml)
- xml_create_xpath($DOM)
- xml_create_DOM($xmlStr)
- xml_get_attribValue($node, $name, $default)
- xml_get_nodeSet($xpathObj,$path,$index=0)
-
▼
April
(24)
1 comment:
Tested 14 April 2007.
Post a Comment