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

  • SEARCH
  • Home
  • 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 8128137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:46:46+00:00 2026-06-06T07:46:46+00:00

i have an form which will send some data to an php file ,

  • 0

i have an form which will send some data to an php file , then return some results as example:

<form action"<?php $_SERVER['PHP_SELF']?>" method="post" id="data">
  <input type"text" name="first_name"/>
  <input type="text" name="last_name"/>
</form>

then in javascript i want catch clcik event in submit form as example :

$("#data").submit(function(){
some code .....
});

which that will prevent the default action for submitting inputs form to the php file , the question is can i send data of a form for php file and same time catch event for the same form ?

NOTE the returned data from php file will be needed by another php
function

  • 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-06-06T07:46:51+00:00Added an answer on June 6, 2026 at 7:46 am

    To prevent the default behavior of form submit(Which is Page reload) you need to use event.preventDefault() like this

    $("#data").submit(function(event){
        event.preventDefault();
        //some code .....
    });
    

    And to post the form data into php without refreshing page you need to use any of the jQuery’s available ajax methods like .post() (Which will send form values using HTTP POST Method) like

    $("#data").submit(function(event){
        event.preventDefault();// prevent page reload
        // Now post the form using Ajax
        // $(this).serialize() will return an array of all form fields as
        //                                                 name value pair 
        $.post('some_script.php',$(this).serialize(),function(data){
            // Just to check if everything is working well
            console.log('Form Submitted Successfully.');
            // do whatever you want with the data
       });
    });
    

    If your php script returns the data in json format the you can either set the content-Type header using php or force jQuery to treat the return data as JSON by specifying the dataType as JSON in the 4th parameter like

       $.post('some_script.php',$(this).serialize(),function(data){
            // Just to check if everything is working well
            console.log('Form Submitted Successfully.');
            // do whatever you want with the data
       },'json');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small web form which will cause a PHP script to send
I have an class which should send/receive data in packet form. This class contains
I'm trying to send POST data to a test.php file, which handles POST data
I have a asp.net web form which will submit information to come as emails.
I have a form where you may press a button which will give you
I have a form which have many check boxes in it. User will check
I have an HTML form which, when submitted by the user, will call a
I have created a macro for excel which will pop up form that contains
I have a form with 2 buttons, that depending on which is selected will
I have a form which POST's its data via AJAX: $.ajax({ type: POST, url:

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.