Hello my friends. I'm trying to understand Ajax. Namely, with the sending data to the server. I have the form
Hello my friends. I'm trying to understand Ajax. Namely, with the sending data to the server.
I have the form, and i need to send to db with ajax
- <form id = "send_form">
- <table>
- <thead id=heading>
- <tr>
- <th>Name
- <th>Age
- <th>Salary
- </tr>
- </thead>
- <tbody id=records
- <tr>
- <td>
- <div class="col-sm-3"><textarea id="emp_name" name="emp_name_n" cols="10" rows="1"></textarea>
- </div>
- </td>
- <td>
- <div class="col-sm-3"><textarea id="emp_age" name="emp_age_n" cols="10" rows="1"></textarea>
- </div>
- </td>
- <td>
- <div class="col-sm-3"><textarea id="emp_salary" name="emp_salary_n" cols="10" rows="1"></textarea>
- </div>
- </td>
- <td>
- <input type="image" id="emp_image" name="emp_image" width="100" height="110">
- </td>
- <td>
- <input type="image" id="emp_image2" name="emp_image2" width="100" height="110">
- </td>
- </tr>
- </tbody>
- </table>
- <input type="submit" class="btn btn-primary" id="send_data" name="send_data" value="Send">
- </div>
- </form>
My PHP
- <?php
- $mo_number = $_POST['emp_name_n'];
- $filter_name = $_POST['emp_age_n'];
- $quantity = $_POST['emp_salary_n'];
- include_once("db_connect.php");
- $sql = "INSERT INTO sender (employee_name_s, employee_age_s, employee_salary_s)
- VALUE ('$mo_number', '$filter_name', '$quantity')";
- $query = mysqli_query($conn,$sql);
- ?>
My Jquery try to do with this
Help plz
- $(document).ready(function(){
- // code to get all records from table via select box
- $("#send_data").click(function() {
- var name = ('#emp_name').val();
- var age = ('#emp_age').val();
- var salary = ('#emp_salary').val();
- $.ajax({
- url:"sender.php",
- method:"POST",
- data: {emp_name_s:name, emp_age_sage:age, emp_salary_s:salary:},
- success:function(data){
- }
- });
- }
- });
- });