Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to set form action via ajax

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 268
    Comment on it

    Hello Reader's If you want to make your form reusable and set the action dynamic via ajax, Then you can make the ajax call like in the example below:-

    <form   id = 'idForm'>
        ...
    </form>
    

    and the script will go like this

    <script>
    // this is the id of the form
    $("#idForm").submit(function(e) {
    
        var url = "action.php"; // the script where you want to put action.
    
        $.ajax({
               type: "POST",
               url: url,
               data: $("#idForm").serialize(), // serializes the form's elements.
               success: function(data)
               {
                   alert(data); // show response from the php script.
               }
             });
    
        e.preventDefault(); // avoid to execute the actual submit of the form.
    });
    </script>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: