Abdul Ashy Abdul Ashy - 5 months ago 19
jQuery Question

AJAX get function in jQuery

Help me get a text field number then make a multiplication table of the number. using AJAX in jQuery. The below script is not working for me

$(document).ready(function(){
var numValue = $("#num").val();
$.get("path.php", {number: numValue} , function(data){
$("#result").html(data);
});
});

Answer

you are trying to get a html element value then request the server then display the fetched details to your browser below is the whole example and i have included the script in it

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="utf-8">

  <title>AJAX</title>

  <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

  <script type="text/javascript">

        $(document).ready(function(){

              $("button").click(function(){

            // Get value from input element on the page
               var numValue = $("#num").val();

            // Send the input data to the server using get
              $.get("../php/create-table.php", {number: numValue} , function(data){

           // Display the returned data in browser
              $("#result").html(data);

    });

  });

});

</script>

</head>

<body>

   <label>A number Between 10 t0 100 <input type="text" id="num"></label>

    <button type="button">Generate Table</button>

         <div id="result"></div>

     </body>

   </html>