Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP form to Ajax type

Tags:

ajax

php

I have a standard form on poll.php:

    <form method="POST" action="createpoll.php">
      ..blah...
    </form>

Is there anyway to process the form without leading the user to createpoll.php, something like calling createpoll.php on submit?

like image 937
CLiown Avatar asked Apr 08 '26 15:04

CLiown


2 Answers

This technology is called AJAX. With help of JAvaScript libraries it's become really easy to use it. You can use JQuery or Prototype. Search for AJAX submission. There are a lot of answers on this topic - i.e., stackoverflow questions.

For exapmle, using JQuery method ajax() it looks like this(JavaScript):

$.ajax({  
        type: "GET",                        // method - Get or Post
    url: "cart.php",                    //  Url to send data
    data: { addproduct: productIDVal, isAjax: 'true'},  // Parameters
    success: function(theResponse) {           
        // code to operate with response, if the request was succesful. 
            // It can be string or array.
    }  
}); 
like image 193
Alex Avatar answered Apr 11 '26 03:04

Alex


A great, extremely easy way to use Ajax in your form can be found here: http://jquery.malsup.com/form/

like image 39
menkes Avatar answered Apr 11 '26 04:04

menkes