Sorry this post went to the wrong thread.

-----Original Message-----
[] On Behalf Of
Sent: Friday, October 30, 2009 12:16 PM
To: Prototype &
Subject: [Proto-Scripty] Simple Ajax form


  I have been trying to construct a simple form by using Prototype,
but without any success. Let me explain what I am trying to do. The
form consists of a single initial button, which is used to enable
(display) the submit button. Then, the submit button makes an Ajax GET
request by means of Prototype to a local PHP file. This PHP file
prints the client's IP address, which should be the content of the
'responseText' field of the Ajax object. Then, the 'responseText' is
shown to the user. Here's the source code:

<!-- index.html -->
<title>AJAX with Prototype</title>
<script type="text/javascript" src="scripts/prototype.js"></script>
<script type="text/javascript">
function Display(id) {
  var element = document.getElementById(id); = "inline";

function Hide(id) {
  var element = document.getElementById(id); = "none";

function makeRequest()
  var url = encodeURIComponent('/getIP.php');
  new Ajax.Request(url, {
    onSuccess: function(transport) {
      var response = transport.responseText || "no response text";
      alert("Success! \n\n" + response);
    onFailure: function(){ alert('Something went wrong...') }

<form method="POST" action="">
<input type="button" value="Show Submit" id="ini_submit" onclick="Hide
<input type="submit" onclick="makeRequest();" name="button"
value="Submit" id="submit_button" style="display: none;"></input>


<!-- getIP.php -->
$remoteip = '';
$remoteip = $_SERVER['REMOTE_ADDR'];
echo $remoteip;

  The code runs smoothly but the 'responseText' is always empty.
  Is there any problem with my PHP file?
  Any ideas?

Thanks in advance!

You received this message because you are subscribed to the Google Groups 
"Prototype &" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to