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.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Param
  • 1
  • 2

1 Answers1

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

Community
  • 1
  • 1
Aaleks
  • 4,283
  • 5
  • 31
  • 39
  • I think its the `onSubmit` event of the form you will pass the AJAX function and not the action attribute – vistajess Dec 10 '15 at 15:24