Sharing an Ajax Request Page - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Sharing an Ajax Request Page

Falkon303Falkon303 Posts: 2Member
Greetings all.

This method uses the same php page to handle all ajax requests,and should be saved as "index.php" accordingly. I am not sure of the security implications, but if anything, I feel this is very handy. Also, I hope you find the usage of "serialize()" as useful as I have. This example requires php, and also the scriptaculous library -

<? if ($_POST['indreq']){echo "regresponse[target]Request Recieved:".$_POST['indreq'];} ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

Woot for Ajax!

window.onload = startfunctions;
function startfunctions()
{$('send').onclick = function() {request();}}
function request()
{new Ajax.Request('index.php', { method: 'post', parameters: { indreq: $('form1').serialize()}, onSuccess: function(p)
{target = p.responseText.split("[target]");$(target[0]).update(target[1]);}})}

label {font-size:11px;color:#333333;font-family:Arial, Helvetica, sans-serif;}
input[type=text]{border:1px solid #333333;font-size:11px;color:#333333;font-family:Arial, Helvetica, sans-serif;}
input[type=password]{border:1px solid #333333;font-size:11px;color:#333333;font-family:Arial, Helvetica, sans-serif;}
input[type=button]{border:1px solid #333333;font-size:11px;color:#333333;font-family:Arial, Helvetica, sans-serif;background-color:#ffffff;}
#regresponse{color:#003300;font-size:11px;font-family:Arial, Helvetica, sans-serif;}

Sign In or Register to comment.