【问题标题】:refresh div in ajaxajax刷新div
【发布时间】:2015-09-09 08:01:00
【问题描述】:

我使用选项值构建搜索查询。我通过 json 代码获取国家、州、城市。我通过 json 代码获取 onload 的国家/地区列表。但是当我更改国家/地区的值时,顶部内容也会在获得结果之前显示分页。加载 img 在分页中可以正常工作,但在选项值中却不行。

这是选择选项图片的第一个链接:-https://www.dropbox.com/s/jvie2x82l2vx4kp/search1.png?dl=0

第二个链接是搜索图片:-https://www.dropbox.com/s/1pe5r5uy9wi19m8/search2.png?dl=0

session_start();
    if(isset($_GET['search']))
    {
        $q=$_GET['profession'];
        $_SESSION['name']=$_GET['profession']; 
    }
    else
    {
        session_unset();         
    }

    if(isset($_GET['country']))
    {
        $_SESSION['country']=$_GET['country']; 
    }

    if(isset($_GET['state']))
    {
        $_SESSION['state']=$_GET['state']; 
    }

    if(isset($_GET['region']))
    {
        $_SESSION['region']=$_GET['region']; 
    }
    enter code here

    <script>
        $(document).ready(function(){
            $("#country").bind("change", function() {
                $.ajax({
                    type: "GET", 
                    data: "country="+$("#country").val(),
                    cache: false,
                    beforeSend: function(){ $("#ajaxLoader").show(); },
                    complete: function(){ $("#ajaxLoader").hide(); },
                    success: function(html) {
                        $("#pagination").html(html).show();
                    }
                });
           });      
       });
   </script>

    <div id="mhead"><h2>Search Result</h2></div>
        <div class="content">
         <body onload="listOfCountries('country');">
        <form>
              <p>Country: 
              <select name="country" id="country" onchange="listOfStatesOrCities(this,'state');"  style="width:150px;"> */
                <option value=""></option>            
                 </select>

              State:
                <select name="state" id="state" onchange="listOfStatesOrCities(this,'region');" style="width:150px;">
                  <option value=""></option>
                </select>

               city: 
                <select name="region" id="region" style="width:150px;" >
                  <option value=""></option>
                </select>
              </p>
        </form> 
        <div id="ajaxLoader" style="display:none"><img src="images/loading.gif" alt="loading..."></div>
        <div id="loading" style="display:none"><img src="images/loading.gif" alt="loading..."></div>
        <div id="pagination" cellspacing="0">
        </div>
    </div>

【问题讨论】:

    标签: php ajax search


    【解决方案1】:

    您可以通过选择器#pagination 仅获取id 为pagination 的div。

    试试这个:

    $("#country").bind("change", function() {
        $("#ajaxLoader").show();
        $("#pagination").load(window.location.href + ' #pagination', { country: $("#country").val() }, function() {    
            $("#ajaxLoader").hide();
        });
    });
    

    【讨论】:

    • 但我在同一页面上得到结果。你可以看到图片的第一个链接。
    • 我尝试了您的查询,但没有得到任何结果。
    • 请给我加载img时选择选项中onchange的ajax代码。
    猜你喜欢
    • 2012-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-23
    • 2016-10-26
    • 2013-09-01
    相关资源
    最近更新 更多