2016-08-02 2 views
0

다시 코드에 아약스가 붙어 있습니다. 내 프로젝트에 대한 라이브 검색 아약스 시스템을 만들고 있지만 search.php에 데이터를 보낼 때 & var_dump POST 배열, 빈 포스트 배열이 나타납니다.아약스를 통해 데이터를 보낸 후에 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을 사용해야합니다. 다음 string이 항상 올바른 방법을 인코딩 것이라는 점을 확실 할 수 있기 때문에,

data : { 
    search : string 
} 

대신 :

그 옆에 당신은 data : "search="+string,하지만 사용을 쓰지한다.

+0

감사합니다. –

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(); 
    } 
    }) 
} 
관련 문제