0

我在 stackoverflow 上搜索过类似的问题,但没有任何帮助。这是我对adding.php 文件的ajax 调用。我在 jquery keyup 事件中调用了这个。当我在浏览器中检查时,我看到 php 文件返回响应。但是,响应的数据永远不会到达ajax的成功函数。

$.ajax({
    url: "anding.php",
    type: "POST",
    dataType: 'json',
    data: JSON.stringify({mycol:mycol,mycolval:mycolval,string:string}),
    contentType: 'application/json',
    success: function(data){
        alert(data);
        var output = data.substring(0, data.indexOf('arventures'));
                        last = data.substring(data.indexOf('arventures') + 10);
                        last--;
                        $('.remove').remove();
                        $('.main_tr').after(output);

                        if (output == '' || output == null) {
                            $('.message').html('No results found.');
                        }
                        else {
                            $('#row1').addClass('highlight');
                        }//highlight row1 by default

                            }

   });

这是我返回响应的 php 文件。我已经粘贴了整个代码,因为我不知道是哪个部分导致了问题。添加.php

<?php
include 'connection.php';
$postdata = json_decode(file_get_contents("php://input"), true);

//var_dump($postdata);exit;
//var_dump($postdata);
$query = "SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = '".$table_name."'
    AND table_schema = '".$mysql_database."'";
$result = mysqli_query($con,$query);


$results = array();
while ($line = mysqli_fetch_assoc($result)) {
    $results[] = $line;
}



$query = null;


foreach ($results as $r) {//search in order.1st search in column 1 then column 2...so on
    $append = " SELECT * from " . $table_name . " WHERE " . $r['COLUMN_NAME'] . " like '" . $postdata['string'] . "%'";
    $query = $query . $append;
    for($i=1;$i<=(count($postdata['mycol']))-1;$i++)
        {
    $append1=" AND " .$postdata['mycol'][$i]. " like '" . $postdata['mycolval'][$i] . "%'";
    $query = $query . $append1;
        }
        $query=$query." UNION";
}
$query = substr($query, 0, -6);



$result2 = mysqli_query($con, $query);
$pos = strrpos($postdata['string'], '%');
$str_count = substr_count($postdata['string'], '%');
$results2 = array();
$results3 =array();
while ($line = mysqli_fetch_assoc($result2)) {
    if (strpos($postdata['string'], '%') !== false || strpos($postdata['string'], '_') !== false) {// highlight in star search
        $str = preg_replace('/[^a-zA-Z0-9-]/', '', $postdata['string']);
        $line = preg_replace("|^($str)|Ui", "<span class='highlights'>$1</span>", $line);
    } else {
        $string=$postdata['string'];
        $line = preg_replace("|^($string)|Ui", "<span class='highlights'>$1</span>", $line); //highlight in normal search 
    }
    $results2[] = $line;
}

$result2 -> data_seek(0);

while ($line1 = mysqli_fetch_assoc($result2)) {

    $results3[] = $line1;
}


for ($i=1;$i<=count($results2);$i++) {

   echo "<tr id='row".$i."' class='remove table_row'>";
   $j=0;
        foreach($results as $r1){
            if($j==0){
                echo "<td class='index_field' dB_id='".$results3[$i-1][$r1['COLUMN_NAME']]."'>".$results2[$i-1][$r1['COLUMN_NAME']]."</td>";
            } else {
                echo "<td>".$results2[$i-1][$r1['COLUMN_NAME']]."</td>";
            }
            $j++;
        }
   echo "</tr>";
}
echo 'arventures' . $i;

mysqli_close($con);
4

1 回答 1

0

您的 ajax 调用永远不会到达成功函数,因为您已将 dataType 指定为 JSON。删除 dataType 或返回 JSON 而不是普通的 HTML。

于 2013-08-11T12:51:38.090 回答