AJAX

Moderators: None (Apply to moderate this forum)
Number of threads: 60
Number of posts: 100

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Sharing an Ajax Request Page Posted by Falkon303 on 6 Oct 2009 at 12:42 PM
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 - http://script.aculo.us/downloads.

<? if ($_POST['indreq']){echo "regresponse[target]Request Recieved:".$_POST['indreq'];} ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Woot for Ajax!</title>
<script src="scripts/prototype.js" type="text/javascript"></script>
<script src="scripts/unittest.js" type="text/javascript"></script>
<script src="scripts/scriptaculous.js" type="text/javascript"></script>
<script type="text/javascript">
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]);}})}
</script>
<style type="text/css">
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;}
#error{float:left;height:200px;padding:20px;color:#003300;}
</style>
</head>
<body>
<form id="form1" name="form1" style="width:150px;">
<label>email address:<input type="text" name="email_address" id="email_address" /></label>
<label>desired password:<input type="password" name="password" id="password" /></label>
<label>repeat password:<input type="password" name="password2" id="password2" /></label>
<p><input type="button" name="send" id="send" value="Register" /></p>
</form>
<div id="regresponse" name="regresponse"></div>
</body>
</html>




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.