2017-09-13 15 views
1
<form> 
       <div class="content-search-block"> 
        <div class="search-bar"> 

         <div class="search-bar"> 

         <input type="text" class="form-control" id="dname" name="dname" value="" placeholder="Otsi töötajaid"> 
         <button type="submit" id="submit" class="icon"><i class="fa fa-search"></i></button> 

        </div> 
       </div> 
       </form> 

私はこの種の検索フィールドを持っています。 JSファイルのこの種の開始(WPのええ)しかし、私のスクリプトdoesentロードボタンを送信しているようですか?Jqueryフィールドの選択

jQuery(document).ready(function(){ 
jQuery('#submit').click(function(){ 
var name = jQuery("#dname").val(); 

私はなぜ

でも

jQuery(document).ready(function(){ 
jQuery('#submit').click(function(){ 
var name = jQuery("#dname").val(); 
jQuery.ajax({ 
url: '/wp-admin/admin-ajax.php', 
type: 'POST', // Adding Post method 
dataType: 'JSON',// Including ajax file 
data: {'action': 'do_search', 'dname':name}, // Sending data dname to post_word_count function. 
success: function(data){ // Show returned data using the function. 
alert(data); 
} 
}); 
}); 
}); 
を試してみましたか?スクリプトはエンキューされ、ページの読み込み時に読み込まれます。 まだナダ。あなたのコードで

+0

HTTPS ://stackoverflow.com/questions/6173238/jquery-event-not-firing – luxdvie

答えて

0

次の3個のdivタグを開いていますが、2個のだけdivタグ

あなたがデフォルトにフォームの送信を防止 に必要
0

閉じ:

jQuery('#submit').click(function(e){ 
    ... 
    e.preventDefault(); 
    // or 
    return false; 
}); 

またはメイクをそれ

<button type="button" ... 
+0

私はそこにvar名も定義できますか? –

+0

私はなぜそうは思わない – Igor

関連する問題