Web Development
 
Your Ad Here
Ajax calls using prototype 
Protoype is an excellent javascript framework that provides an easy way to make ajax calls.

Here is the sample code of how to make the call:

//first I am passing a variable that I call id, this would be the row id for the database table being used, for example: if I'm updating the record with the id of 4, I would call: javascript:dosomethingAjax('4');
//the id is passed to the file dosome.php that will handle whatever it is you are trying to do
//if you want to pass more variables through the ajax call you would use commas to separate them, for example: parameters: {u: id, name: 'John', age: 24}

function dosomethingAjax(id) {
var myAjax = new Ajax.Request('dosome.php',
{method: 'get', parameters: {u: id},
onComplete: handleResponse});
}
//once dosome.php gets processed, the ajax call is complete and the following function is called, in this case, I am putting the results inside a div with the id of displayResults
function handleResponse(transport) {
document.getElementById('displayResults').innerHTML = transport.responseText;
}

//here is how to setup the dosome.php

<?php
//the variable u is being passed by the ajax call listed above
$id = $_GET['u'];
//do something like update or insert or select
echo "Success!";
?>

[ add comment ] ( 23 views )   |  permalink  |  related link  |   ( 3 / 190 )

<Back | 1 | 2 | 3 | 4 | Next> Last>>


Home | Portfolio | Hosting | Web Development | Contact Us
© 2007 dpwebservices.net. All right reserved.