0

The following is my react code

var AddRecord = React.createClass({
    componentDidMount: function() {


    },
    render: function() {
        return (
         <form action="process.php" method="post">
            <table><tr><td>Enter Id</td><td><input type="text" name="Id"/></td></tr>
                   <tr><td>Enter Name</td><td><input type="text" name="name"/></td></tr>
                   <tr><td>Enter Email</td><td><input type="text" name="Email"/></td></tr>
                   <tr><td>Enter Phone</td><td><input type="text" name="Phone"/></td></tr>
                   <tr><td>Enter Marks</td><td><input type="text" name="Marks"/></td></tr>
                   <tr><td></td><td><input type="submit" name="submit" value="submit"/></td></tr>
             </table>
           </form>
        );
    }
});

React.render(<AddRecord/>, document.getElementById('form-data'));

I just want to send this data through AJAX in a json format in react js.

1 Answer 1

0

You can use the serialize JQuery function to serialize the code in an handleSumit function. You can also do the serialization by hand.

  <form onSubmit={this._handleSubmit}>
            <input type="text" name="Id"/>      
            <input type="text" name="name"/>
            <input type="submit" value="Submit the form"/>
  </form>

then in the handle submit function you can

_handleSubmit(e){
    e.preventDefault();
  if (valid) {
   //serialize the form and send ajax request
  }
}

jQuery AJAX form data serialize using PHP if you use JQuery to do your ajax request

Sign up to request clarification or add additional context in comments.

1 Comment

I think its the onSubmit event of the form you will pass the AJAX function and not the action attribute

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.