1
我有這個文本框用於檢查數據庫上的名稱,它提供了答案和一切,但如果我把console.log(data)
它不回答。JQuery AJAX請求的答案,但沒有成功
這裏是我的代碼:
function absurdSearch(textoBuscar){
$.ajax({
type : "POST",
url : "service.php",
dataType: "json",
data : {
action:"absurdSearch",
absurdText: textoBuscar
},
success:function(data){
console.log(data);
$("#fotoproyectosarq").empty();
var html = '';
html += '<img src="' + data.path + '" height="128" width="160">';
$("#fotoproyectosarq").append(html);
$("#nombreproyectosarq").empty();
var html2 = '';
html2 += "<form method=\"post\" name=\"projectsearch\" id=\"projectsearcharq\" action=\"proyectos_arq.php\">"
html2 += "<span style=\"cursor: pointer;\" onclick=\"document.getElementById('projectsearcharq').submit()\">"+ data.projectName +"</span>"
//html2 += "<button id=" + "button" + data.projectId + " style=\"visibility:hidden;\"><span id=" + data.projectId + " style=\"cursor: pointer;\"><span>" + data.projectName + "</span></span></button>"
html2 += "<input name=\"project_id\" type=\"hidden\" id=\"project_id\" value=" + data.projectId + ">"
html2 += "</form>"
$("#nombreproyectosarq").append(html2);
}
})
}
$('#buscadorRapidoTextInput').on('keyup', function() {
var textoBuscar = $(this).attr('value');
absurdSearch(textoBuscar);
});
和服務answersaccording到螢火蟲:
memphis{"projectCategory":"1","projectId":"5","projectName":"MEMPHIS RIVERFRONT","path":"server\/php\/files\/MF_1.jpg"}
但成功事件似乎並沒有工作。
這裏的後端代碼:
function absurdSearch($absurdText){
$db = new db();
$conn = $db->conn();
$SQL_ABSURD_SEARCH="SELECT projects.id as projectId, projects.project_types_id as projectCategory, projects.name as projectName, projects.description as description, path FROM projects INNER JOIN project_types ON (projects.project_types_id = project_types.id) inner join images on images.projects_id = projects.id where images.main = '1' and projects.name LIKE '%$absurdText%' LIMIT 1";
$conn->query($SQL_ABSURD_SEARCH);
foreach($conn->query($SQL_ABSURD_SEARCH) as $row) {
$projectCategory = $row['projectCategory'];
$projectId = $row['projectId'];
$projectName = $row['projectName'];
$path = "server/php/files/".$row['path']."";
$rows = array("projectCategory" => $projectCategory,"projectId" => $projectId, "projectName" => $projectName, "path" => $path);
$json = json_encode($rows);
echo $json;
}
}
也許我錯了,但是這是每一個產生太多的html按鍵 – Ibu
我認爲這只是異步問題。嘗試在選項中將'async'設置爲'false'。 –
嘗試一個警報,這將告訴你,如果它是成功的。 –