weixin_33733810 2016-01-13 10:22 采纳率: 0%
浏览 8

实时搜索Ajax

i have been table site for some time now and i implemented a searching system, but i want it to be real time search so whenever you press a button it will refresh the site. I have little coding experiance so ill ask for some help here.

Here is my ajax code:

function searchDomains() {
    $.ajax({
        type: "POST",
        url: "Ajax/searchDomain.action.php",
        data: {
            domain: $('input[name="domain"]').val(),
            width: $(window).width()
        },
        success: function(data) {
            $("#container_domains").html(data);
        }
    });
}
  • 写回答

1条回答 默认 最新

  • weixin_33691817 2016-01-13 10:26
    关注

    You are almost right, but you need to attach this function to the keyup event of the <input /> and make it unobtrusive too:

    <input type="text" name="search" id="search" />
    <div id="container_domains"></div>
    

    And in the jQuery:

    $(function () {
      $("#search").keyup(function () {
        $.ajax({
          type: "POST",
          url: "Ajax/searchDomain.action.php",
          data: {
            domain: $('input[name="domain"]').val(),
            width: $(window).width()
          },
          success: function(data) {
            $("#container_domains").html(data).show();
          }
        });
      });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度