我在php中創建了一個簡單的搜索函數。它的工作時,我沒有使用Ajax的腳本。但是當我使用ajax時,我的內爆函數消失了。如何在ajax調用發送時使用PHP中的數組獲取數據
這裏是我的代碼的樣子。
$searchtag = filter_var($_GET['search'], FILTER_SANITIZE_STRING);
$searchtagrlce = str_replace("+", " ", $searchtag);
$searchTermsis = explode(' ', $searchtagrlce);
$searchTermBitsis = array();
foreach ($searchTermsis as $terms) {
$terms = trim($terms);
if (!empty($terms)) {
$searchTermBitsis[] = "tbale_row1 LIKE '%$terms%' OR tbale_row12 LIKE '%$terms%' OR tbale_row13 LIKE '%$terms%'";
}
}
$getdataquerystores = "SELECT `tbale_row1`, `tbale_row2`, `tbale_row3`, `tbale_row4`, `tbale_row5`, `tbale_row6` FROM `tablename` WHERE ".implode(' AND ', $searchTermBitsis). " ORDER BY tbale_row1 DESC LIMIT $limit, 10";
$getdataquerystoress = mysqli_query($connection, $getdataquerystores);
當我回聲或打印沒有Ajax上述代碼,即時得到此
SELECT `tbale_row1`, `tbale_row2`, `tbale_row3`, `tbale_row4`, `tbale_row5`, `tbale_row5` FROM `tablename` WHERE tbale_row1 LIKE '%a%' OR tbale_row2 LIKE '%a%' OR tbale_row3 LIKE '%a%' ORDER BY tbale_row1 DESC LIMIT 0, 10
但是當我使用AJAX和列印以上相同的代碼,即時獲取此(後功能數據已經DI SAPPEAR)
SELECT `tbale_row1`, `tbale_row2`, `tbale_row3`, `Logo_croped_554`, `tbale_row5, `tbale_row6` FROM `tablename` WHERE ORDER BY tbale_row1 DESC LIMIT 10, 10
這裏是我的Ajax代碼
$(window).scroll(function()
{
\t if($(document).height() <= $(window).scrollTop() + $(window).height())
\t {
\t \t loadmore();
\t }
});
function loadmore()
{
var val = $("#row_no").val();
$.ajax({
type: 'post',
url: '/myproject/data/alldata.php',
data: {
getresult:val
},
\t beforeSend:function(){
\t \t $(".loading-data").fadeIn("slow");
\t },
\t
\t uploadProgress:function(){
\t \t
\t \t $(".loading-data").fadeIn("slow");
\t },
success: function (response) {
\t var content = document.getElementById("dsdplasdy_sdtres");
content.innerHTML = content.innerHTML+response;
\t
document.getElementById("row_no").value = Number(val)+10;
\t },
\t complete:function() {
\t \t $(".loading-data").fadeOut("slow");
\t \t
\t }
\t
});
}
這裏是值Im從TNE隱藏字段越來越
<input type="hidden" id="row_no" value="10" />
請任何EX [ERT可以幫助我。任何幫助非常感謝。謝謝。
您好@Ralpha,Im不填充任何形式的或提交的任何數據。我只是檢索數據,當用戶滾動到頁面的底部,從最後一個ID到下一個數據。我只有這個〜implode〜函數纔有這個麻煩。我用我的ajax代碼使用了其他腳本,他們正在工作。有什麼建議麼 ? – alex
亞歷克斯,我已經檢查了你的代碼,它是一個JavaScript的方法後,這意味着數據將顯示在超全局$ _POST ['getresult']的形式等效,無論你的問題是重複的。 –