Sorry this post went to the wrong thread.


-----Original Message-----
From: prototype-scriptaculous@googlegroups.com
[mailto:prototype-scriptacul...@googlegroups.com] On Behalf Of
vicente.batista
Sent: Friday, October 30, 2009 12:16 PM
To: Prototype & script.aculo.us
Subject: [Proto-Scripty] Simple Ajax form


Dears,

  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 -->
<html>
<head>
<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);
  element.style.display = "inline";
}

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

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

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

</body>
</html>

<!-- getIP.php -->
<?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 & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to