Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Simple Ajax form
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
vicente.batista  
View profile  
 More options Oct 30, 12:15 pm
From: "vicente.batista" <vicentehel...@gmail.com>
Date: Fri, 30 Oct 2009 09:15:47 -0700 (PDT)
Local: Fri, Oct 30 2009 12:15 pm
Subject: 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!


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Haston  
View profile  
 More options Nov 1, 11:25 am
From: "Michael Haston" <mich...@haston.name>
Date: Sun, 1 Nov 2009 11:25:31 -0500
Local: Sun, Nov 1 2009 11:25 am
Subject: RE: [Proto-Scripty] Simple Ajax form
JSON response ... {"success" : "true", "message" : "good"}

Code ...

            function ajaxRequest2(){
                var url = "/cgidev2p/r_chgpwd.pgm";
                var pars = 'v_current=' + escape($F('v_current')) +
'&v_new=' + escape($F('v_new')) + '&v_confirm=' + escape($F('v_confirm')) +
'&sessionid=' + escape($F('sessionid'));
                //var submitObj = document.getElementById('goButton');
                new Ajax.Request(url, {
                    method: 'get',
                    //contentType: 'application/json',
                    parameters: pars,
                    onSuccess: function(transport){
                        alert("Success");
                        var json = transport.responseJSON;
                        alert(json.success);
                    }
                                        , onError: function(transport){
                                                alert("skipped");
                                        }
                    , onComplete: function(transport){
                        alert("Complete");
                    }
                });
            }

Alerts that I see are Success and Complete.  The alert(json.success) does
not fire.

If I change the code to alert(json) the alert fires with "null".


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Haston  
View profile  
 More options Nov 1, 11:27 am
From: "Michael Haston" <mich...@haston.name>
Date: Sun, 1 Nov 2009 11:27:36 -0500
Local: Sun, Nov 1 2009 11:27 am
Subject: RE: [Proto-Scripty] Simple Ajax form
Sorry this post went to the wrong thread.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dave Kibble  
View profile  
 More options Nov 3, 8:53 am
From: Dave Kibble <davekib...@gmail.com>
Date: Tue, 3 Nov 2009 13:53:59 +0000
Local: Tues, Nov 3 2009 8:53 am
Subject: Re: [Proto-Scripty] Simple Ajax form
What happens if you type <your server>/getIP.php into a browser address bar?

Your PHP should emit a valid HTML file (i.e. include head and body
tags), but I don't know if that would necessarily stop it working.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vicente h.f. Batista  
View profile  
 More options Nov 3, 12:38 pm
From: "Vicente h.f. Batista" <vicente.hel...@gmail.com>
Date: Tue, 3 Nov 2009 15:38:39 -0200
Local: Tues, Nov 3 2009 12:38 pm
Subject: Re: [Proto-Scripty] Re: Simple Ajax form
Hi Dave,

  The PHP correctly emits the IP. Yesterday, I caught the problem.
After the following modifications:

function makeRequest()
{
  var url = 'getIP.php';
  ...

}

and

<form method="POST" action="" onsubmit="makeRequest(); return false;" >
...
<input type="submit" name="button" value="Submit" id="submit_button"
style="display: none;"></input>
...

the code has worked.

Anyway, thank you very much!


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google