send data through ajax in react js

By : Param

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>

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

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

By : Param


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"/>

then in the handle submit function you can

  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

By : Aaleks

This video can help you solving your question :)
By: admin