How do you send an ajax request every time that a form input field changes?

前端 未结 4 1478
花落未央
花落未央 2021-02-09 05:34

For example, there is an input field. Every time a user types a key into that field, it sends an AJAX request with whatever text is currently in that input, and does something

4条回答
  •  猫巷女王i
    2021-02-09 05:41

    I'd probably do something similar to this. you'd have to add some extra code to handle dropdowns, but the idea is the same.

    $('form input').keyup(function () {
        $.ajax({
          type: "POST",
          url: url,
          data: data,
          success: success,
          dataType: dataType
        });
    });
    

提交回复
热议问题