2015-10-08 36 views
0

我已經構建了一些輸入來讓用戶搜索數據庫。搜索正在使用ajax請求。

我的問題是因爲當我從服務器獲得響應時,我也會得到搜索輸入。我不想那樣。

看看我的代碼:

<script> 
    $(document).on('change', '.auto-select', function(e){ 

     e.preventDefault(); 

     var tags = $('#auto-tag-script').serialize(); 
     var contracts = $('#auto-contract-script').serialize(); 
     var educations = $('#auto-education-script').serialize(); 
     var towns = $('#auto-town-script').serialize(); 

     runAjax(tags, contracts, educations, towns); 

    }); 

    function runAjax(tags, contracts, educations, towns) { 
     $.ajax({ 
      url: 'http://localhost/jobs/public/anazitisi-ergasias?' + tags + '&' + contracts + '&' + educations + '&' + towns 
     }).done(function(data){ 

      $('div.show-html-from-ajax').html(data); 

     }); 

    } 

</script> 

使用上面的代碼,輸入將再次出現在我的頁面中。

有什麼辦法可以逃脫這種形式的輸入。

+0

粘貼你的HTML給我們:) – Buzinas

+0

沒有你的服務器端腳本輸出你不想使用的任何東西。 –

回答

1

您插入它(最好的方法)之前,您可以將其隱藏2種方式......或之後將其插入

$.ajax({ 
     url: '...' 
    }).done(function(data){ 
     // create jQuery object from response 
     var $html = $(data); 
     //hide within that object 
     $html.find('.search-form-for-hide').hide(); 
     // insert the object 
     $('div.show-html-from-ajax').html($html); 
     /******* OR ***************/ 
     // the html is in the DOM now, can do whatever might be needed to it 
     $('.search-form-for-hide').hide(); 

    }); 

對於你需要插入,然後再調用插件

+0

非常感謝我的朋友。它完美的作品! :) –

0
許多插件

使用jQuery,您可以使用$(data)jQuery(data)(請參閱this doc)將DOM對象或html字符串隱式轉換爲jQuery對象。然後使用$(data).find('.search-form-for-hide').hide()來查找元素並隱藏它。