简体   繁体   English

如何将多个ajax调用的结果填充到相同的div ID中?

[英]how to fill result of multiple ajax call into same div id?

I have two autocomplete textbox. 我有两个自动完成文本框。 I would to like to fill the ajax results in same div so that style will be the same for both div. 我想在相同的div中填充ajax结果,以便两个div的样式都相同。 how to achieve this on keyup. 如何在keyup上实现这一目标。 Is it possible to add like t his 是否可以像他一样添加

$("#main_search").keyup(function(){
 var el = $(this);
//alert("hi");
  if (e.which !== 38 && e.which !== 40 && e.which !== 13) {
            delay(function() {
    $.ajax({
    type: "POST",
    url: "<?php echo base_url('search_jobs/get_category'); ?>",
    data:'term='+$(this).val(),
    //beforeSend: function(){
 //         $('#loader-icon').show();
 //     },
    success: function(data){
        //alert(data);
        $("#suggesstion-box").show();
        $("#suggesstion-box ul li").css("border","1px solid red");
        $("#suggesstion-box").html(data);
        $("#search-box").css("background","#FFF");
    }
     });
            }, 400);


    });
}); 


$("#location_search").keyup(function(){
 var el = $(this);
 if (e.which !== 38 && e.which !== 40 && e.which !== 13) {
            delay(function() {
    $.ajax({
    type: "POST",
    url: "<?php echo base_url('search_jobs/get_location'); ?>",
    data:'term='+$(this).val(),

    success: function(data){
        $("#suggesstion-box").show();
        $("#suggesstion-box").html(data);
        $("#location_search").css("background","#FFF");
    }
    });
}); 

Change this line: 更改此行:

$("#suggesstion-box").html(data);

to

$("#suggesstion-box").append(data);

This will keep appending in the box, you might need to clear the suggestion box at certain time depending on your flow. 这将继续添加到框中,您可能需要在特定时间清除建议框,具体取决于您的流程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM