Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6364461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:09:59+00:00 2026-05-25T00:09:59+00:00

I want post a form with jquery, but my code not work. after I

  • 0

I want post a form with jquery, but my code not work. after I submit it, my page will refresh, where is the problem? wait for a help.

jquery code

function submitForm() {
        var par1 = $('input[@name=my_radio][@checked]').val();
        var par2 = $('input[@name=title]').val();
        var par3 = $('input[@name=content]').val();
            $.ajax({
                url: "r8.php", 
                dataType: "html",
                type: 'POST', 
                data: "submit=" + par1 + "&title=" + par2 + "&content=" + par3, 
                success: function(data){ 
                    $("#response").html(data);
                    $('input[@name=title]').html('');
                    $('input[@name=content]').html('');
                }
            });

        return false;
    } 

html code:

<form method="post" id="post_form" name="post_form" onsubmit="return submitForm();">
    <label>1: <input type="radio" name="my_radio" value="1" checked /></label>   
    <label>2: <input type="radio" name="my_radio" value="2" /></label> 
    <input id="title" name="title" type="text">
    <input id="content" name="content" type="text">
    <input type="submit" name="my_submit" id="my_submit" value="submit" />
</form>
<div id="response"></div>

and r8.php code

<?php
if($_POST['submit']!=''){ 

    echo $_POST['title']."|".$_POST['content']."|".$_POST['submit']."|".time(); 

}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:09:59+00:00Added an answer on May 25, 2026 at 12:09 am

    in your java script submitform() function, recieve values like this:

    var par1 = $('input:radio[name=my_radio]:checked').val()
    var par2 = $('#title').val();
    var par3 = $('#content').val();
    

    your method is not getting the values in the variables. thats why nothing is being posted.
    I’ve tried it and it works.

    EDIT:

    What you would need to do is use one of the ajax methods to post your form, and inject the output into an element within the success callback. For example:

    $("#my_submit").click(function() {
        $.post($("#post_form").attr("action"), $("#post_form").serialize(), function(html) {
            $("div.post_form").html(html);
        });
        return false; // prevent normal submit
    });
    

    Take a look at

    http://api.jquery.com/jQuery.post/
    and
    http://api.jquery.com/jQuery.ajax/

    give r8.php in your form action attribute. i.e.

    <form method="post" id="post_form" name="post_form" action="r8.php" />
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to test jquery post. I am posting a form and want
I have an action handling a form post, but I want to make sure
I want to ignore the post form in the django's internatonalization. I am using
I want to make a form like this, and i want to post the
I have a nested json. I want to post it as a form input
I want to do an HTTP POST that looks like an HMTL form posted
I have an ASP.NET application in which i want to post data using jQuery
I'm using a basic registration form with AJAX, but the form is not connecting
I'm using jQuery with PHP for form validation. I want to return the fields
I've noticed that when using $.post() in jquery that the default contentType is application/x-www-form-urlencoded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.