2016-08-02 2 views
0

もう一度私のコードでajaxが残っています。私は私のプロジェクトのライブ検索ajaxシステムを作っていますが、データをsearch.php &に送信すると、var_dump POST配列は空のポスト配列になります。ajaxを介して送信されたデータの後にPOST配列が空です

AJAX

function searching(string){ 
$.ajax({ 
    url : "request/search.php", 
    type : "POST", 
    data : "search="+string, 
    type : "text", 
    beforeSend : function(http){ 

    }, 
    success : function(response,status,http){ 
    alert(response); 
    }, 
    error : function(http,status,error){ 
     $('.response').html("<span class='error'>Something went wrong</span>"); 
     $(".response").slideDown(); 
    } 
    }) 
} 

HTML

<form id="searchBox"> 
    <p> 
     <input type="text" name="search" id="search" onkeyup="searching(this.value)" placeholder="Search here"> 
     <button class="find" data-icon="&#xe986;"></button> 
    </p> 
    </form> 

答えて

0

あなたのtype : "POST",type : "text",で上書きします。したがって、type : "text",を削除する必要があり、jQuery 1.9以降はtypeの代わりにmethodを使用する必要があります。その横に

あなたはdata : "search="+string,が、使用することを書くべきではありません。代わりに

data : { 
    search : string 
} 

、その後、あなたはstringが常に正しい方法でエンコードされることを確認することができますので。

+0

oopのおかげで私は気付かなかった –

0
function searching(string){ 

$.ajax({ 
    url : "request/search.php", 
    type : "POST", 
    data : {'search': string}, 
    type : "text", 
    beforeSend : function(http){ 

    }, 
success : function(response,status,http){ 
    alert(response); 
    }, 
error : function(http,status,error){ 
    $('.response').html("<span class='error'>Something went wrong</span>"); 
    $(".response").slideDown(); 
    } 
    }) 
} 
関連する問題