sumit
sumit

Reputation: 11257

HTML GET and POST methods

Is it necessarily required that the action="abc.php" in FORM tag must have a PHP, JSP, ASP file? Can't simple HTML code display the data submitted in the FORM?

In other words,

FILE: abc.html

<form method="post" action="xyz.html">
     <input type="text" name="name" id="name" value="Enter your name here" />
</form>

OR

<form method="get" action="xyz.html">
         <input type="text" name="name" id="name" value="Enter your name here" />
</form>

Now in file xyz.html, can I display the name entered in abc.html using only HTML code?

Upvotes: 6

Views: 2896

Answers (7)

Surinder ツ
Surinder ツ

Reputation: 1788

You can do it using jQuery Ajax method.


$(document).ready(function(){
          ajaxFunction();
});
    function ajaxFunction() {
        var postdata = jQuery("#form").serialize();
        jQuery.ajax({
            url: "xyz.html",
            type: "POST",
            data: postdata,
            success: function(response){
                    console.log(response);
            },
            error: function(){
                console.log(response);
            }
        });
    } 

reference

Upvotes: 0

ltdev
ltdev

Reputation: 4457

you need a server side language in order to process the form and grab the data from the user. In PHP, at least, as I know you can leave the action="" empty which means you will process the form on the same page

Upvotes: 2

Levin
Levin

Reputation: 194

No, you can't. Cause the post data transfer to the server, and the server can't deal with the data with simple HTML code except a server language like PHP, PYTHON, JAVA etc.

Upvotes: 2

웃웃웃웃웃
웃웃웃웃웃

Reputation: 11984

You cannot dispaly it using html only. You need to have a server side scripting language like PHP,ASP.Net or java etc...

Upvotes: 3

Tepken Vannkorn
Tepken Vannkorn

Reputation: 9713

The purpose of using those server side extension is to manipulate the data sent from the form elments on the server with the method of POST or GET, but if you only want to show the data entered on the browser, you can send it to the .html file because they do not need to be manipulated at all.

Upvotes: 2

jap1968
jap1968

Reputation: 7763

Yes, you could do it with plain html + javascript. As an example you can retrieve http parameters by using jQuery. More information available here:

Get escaped URL parameter

Upvotes: 0

Jan Hančič
Jan Hančič

Reputation: 53931

HTML by itself can't access submitted POST/GET data. You need a server side language (PHP, python, ruby, .NET, ...) to put those values into HTML.

That being said, you can post to a HTML page, you just won't be able to do anything with it.

You could use JavaScript to access GET variables, but not POST.

Upvotes: 5

Related Questions