I been playing recently with
Protoype, so i thought as a good experience, to update this post with the alternative code needed to run the script with this Library.
First we need to make a modification to our
index.html, we of course have to include the Prototype Library but also modify two values on our call to request_action:
index.html:
HTML Code:
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/ajax.js" type="text/javascript"></script>
<input id="email" name="email" type="text" />
<input id="subscribe" name="subscribe" type="button" onclick="request_action('suscribenews.php', 'add&email='+$('email').value, 'target')" value="Subscribe"/>
<input id="unsubscribe" name="unsubscribe" type="button" onclick="request_action('suscribenews.php', 'delete&email='+$('email').value, 'target')" value="Unsubscribe"/>
<div id="target"></div>
Once thats done we have to make another slightly change, but this time to
ajax.js:
Code:
function request_action(jurl,jdata,jtarget)
{
$(target).innerHTML = "Processing request...";
var myAjax = new Ajax.Updater(jtarget, jurl, { method: 'get', parameters: jdata});
}
And thats it!, pretty simple and pretty similar. Hope you find it useful!