私信  •  关注

jpneey

jpneey 最近创建的主题
jpneey 最近回复了
4 年前
回复了 jpneey 创建的主题 » 从用户输入号码到更新可用数量的jquery ajax调用

您应该监听输入值的变化,然后运行ajax调用。然后在成功后,呈现后端的响应

<table id="myTable">
        <tr>
        <th>Product Line</th>
        <th >Quantity</th>
        <th>Available Quantity</th>
        </tr>
        <tr>
            <td id="product-number">test product <br> 56789</td>
            <td><input type="number" id="product-quantity" name="quantity" min="1" max="999"></td>
            <td id="available-quantity"></td>
        </tr>  
</table>
$(function(){
    $('#product-quantity').on('keyup', function() {
       // if input value is changed, run the ajax call here
       $.ajax({
          .... <- fill in all required details here such as url, method, etc.
          success: function (data) {
            // then on ajax success, display the results from your backend
            $('#available-quantity').html(data)
          }
       })
    })
})

关于如何通过jquery调用ajax的参考: https://api.jquery.com/jquery.ajax/