gpt4 book ai didi

Jquery SQL 数组 WordPress

转载 作者:行者123 更新时间:2023-11-29 18:27:17 26 4
gpt4 key购买 nike

我在使用 PHP 在 Wordpress 中填充 Sql 数组时遇到问题。

我有search.html

<form action="" method="post">
<input type="text" placeholder="Name" id="customerAutocomplte" class="ui-autocomplete-input" autocomplete="on" />
</form>

<script src="js/jquery.ui.autocomplete.html.js" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$.noConflict();
$(document).ready(function($){
$('#customerAutocomplte').autocomplete({
source:'suggest_name.php',
minLength:2
});
});
</script>
</head>

这是 suggest_name.php

/* Attempt MySQL server connection */
$link = mysqli_connect("localhost", "root", "mysql", "wordpress");

// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
else {
$link->set_charset('utf8');
}
/* retrieve the search term that autocomplete sends */
$term = trim(strip_tags($_GET['term']));
$a_json = array();
$a_json_row = array();
if ($data = $link->query("SELECT * FROM persons WHERE first_name LIKE '%$term%' OR last_name LIKE '%$term%' ORDER BY first_name , last_name")) {
while($row = mysqli_fetch_array($data)) {
$first_name = htmlentities(stripslashes($row['first_name ']));
$last_name = htmlentities(stripslashes($row['last_name']));
$code = htmlentities(stripslashes($row['customer_code']));
$a_json_row["id"] = $code;
$a_json_row["value"] = $first_name.' '.$last_name;
$a_json_row["label"] = $first_name.' '.$last_name;
array_push($a_json, $a_json_row);
}
}
// jQuery wants JSON data
echo json_encode($a_json);
flush();

我的sql表

"persons"

有 4 列

"first_name" "last_name" "email" and "customer_code"

“Customer_code”是“AI”主键。我的问题是搜索不会自动填充或填充数组,什么都没有,sql 数据库包含条目,谢谢。

最佳答案

根据 documentation您要么需要指定 appendTo 选择器,要么输入需要具有 ui-front 类的同级选择器。

根据the same documentation ,您的可以是数组字符串函数(对象请求,函数响应(对象数据))。您使用的是 PHP 文件,但两者都不是。您必须编写一个可以向 php 文件发送信息和从 php 文件接收信息的函数才能使其正常工作。 AJAX可能是此类脚本的最佳选择,因为它允许异步通信(即无需重新加载页面即可与 PHP“对话”)。

这两个问题本身就足以破坏您的代码。我可能错过了其他东西,但我建议首先修复这两件事。

关于Jquery SQL 数组 WordPress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46064379/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com