| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| NamePros Regular | This ajax is giving me hell. It's suposed to use posting of data and XML Trees. Im working on my site, Not like i can get it to post anyways, but the php backend already works. Depending on the $_POST['id'], it'll return a tree like this: <id>1</id> <title>Title</title> <links>Links</links> <cont>Cont</cont> <banner>0</banner> Alright, so how to i get all these values into strings, so i can use the functions that i already wrote for them. So, in short... How to get ajax to post, and how do i get it to get the reply from the file that it posted to? If you think you might be able to do this, MSN me at admin@cvxdes.com, i'll pay. Last edited by cvxes; 03-25-2006 at 08:31 PM. |
| |
| | #3 (permalink) |
| NamePros Member | This AJAX code we use can do both POST/GET. Also, there are available AJAX libraries you can use to simplify the job. Code: function createRequestObject() {
var $vObj;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
$vObj = new XMLHttpRequest();
if ($vObj.overrideMimeType) {
$vObj.overrideMimeType('text/xml');
} // fi
} else if (window.ActiveXObject) { // IE
try {
$vObj = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
$vObj = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
} // fi
if (!$vObj) { // failed, cannot create
return false;
} // fi
} // fi
return $vObj;
}
var $vAJAX = createRequestObject();
var $globAJAXBusy = false;
function checkAJAX() {
if ($globAJAXBusy) {
$vAJAX.onreadystatechange = function () {}
$vAJAX.abort();
} // fi
}
function requestPage($pURL) {
checkAJAX();
$vAJAX.open('GET',$pURL,true);
$globAJAXBusy = true;
$vAJAX.onreadystatechange = handleResponse;
$vAJAX.send(null);
}
function postPage($pURL,$pParams) {
checkAJAX();
$vAJAX.open('POST',$pURL,true);
$globAJAXBusy = true;
$vAJAX.setRequestHeader("Content-type","application/x-www-form-urlencoded");
$vAJAX.setRequestHeader("Content-length",$pParams.length);
$vAJAX.setRequestHeader("Connection","close");
$vAJAX.send($pParams);
$vAJAX.onreadystatechange = handleResponse;
}
function handleResponse() {
if(typeof($vAJAX)=='undefined' || $vAJAX.readyState!=4){
return false;
} // fi
try {
if ($vAJAX.status!=200) { // error page
return false;
} // fi
} catch(e) {
return false;
}
$globAJAXBusy = false;
var $vResult = $vAJAX.responseXML;
..... // do something
}
__________________ 123finder.com - Browse dictionary domains & 4-9 letter domains |
| |
| | #4 (permalink) |
| NamePros Regular | If you have AJAX code and you don't want people to use the back button, is there a way to disable the backbutton the the Browser or the Mouse if they have one there?
__________________ DarkNeoNetwork |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |