weixin_33701251 2016-06-13 19:10 采纳率: 0%
浏览 28

jQuery中的AJAX获取功能

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);
    });
 });
  • 写回答

1条回答 默认 最新

  • weixin_33701251 2016-06-13 19:20
    关注

    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>
    
    评论

报告相同问题?