donglu4159 2016-10-27 14:34
浏览 64
已采纳

Bootstrap 3 - 以模态显示ajax搜索结果,然后将模式发布到其他位置

I have a text input where a user can perform a search (for a username or email address held in a database). I already have a PHP script which does the searching etc.

I want to display the search results in a Bootstrap 3 modal - or an error message if there are none.

I'm struggling to understand the full logic of doing this.

What I have so far:

Search input and button:

<input type="text" name="search">
<button id="searchBtn">Search</button>

PHP function (accessible via /ajax/search/) which accepts POST data (e.g. $_POST['search']), queries the database. At the moment this returns an array - empty if no results.

What is the correct order to run things? I know that I need to pass my search input to /ajax/search/. But I also need to open a modal - both of these are presumably done on clicking Search (searchBtn). Do I submit the form with jquery's ajax method first, and then get the success to open the modal?

To further complicate matters, once this modal is shown there will be a series of tickboxes next to users that were found. This will need to be posted elsewhere... But I'm not even getting this far yet.

I'm struggling to understand this and have read a few posts already such as Bootstrap 3 with remote Modal and this Placing the results of a form post into a modal in Bootstrap 3

If there are any tutorials which show this please could someone point me at one as I can't find one, particularly where things aren't marked "this has been deprecated".

  • 写回答

2条回答 默认 最新

  • doudiaozhi6658 2016-10-27 14:52
    关注

    A simple example to consider:

    JS

    $('#myModal').on('shown.bs.modal', function() {
      $(".modal-body").html("Loading...");
      $.ajax({
        url: "/path/to/request",
        data: { 
             // Parameters if needed
        },
        method: "POST",
        success: function(data) {
          $(".modal-body").html(data);
        }
      })
    });
    

    Example (mockup) at:

    https://jsfiddle.net/4bkhLatg/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测