javascript - 我正在尝试使用 ajax POST 方法从 html 页面将数据发送到我的 PHP 页面,但它给出了错误,注意:未定义的索引:
问题描述
<head>
<title>Document</title>
<script>
$(document).ready(function () {
$("#search").on("keyup", function () {
var search_term = $(this).val();
console.log('value--', search_term)
$.ajax({
url: "ajax-live-search.php",
type: "POST",
data: { search: search_term },
success: function (ajaxresult) {
$("table-data").html(ajaxresult);
}
});
});
});
</script>
</head>
<body>
<div id="search-bar">
<label>Search</label>
<input type="text" id="search" autocomplete="off">
</div>
<div id="table-data">
</div>
</body>
PHP 页面
$search_input = $_POST["search"];
echo $search_input;
错误
注意:未定义索引:在第 3 行的 C:\xampp\htdocs\ajax\ajax-live-search.php 中搜索
解决方案
将“类型”更改为“方法”,如下所示:
$.ajax({
url: "ajax-live-search.php",
method: "POST",
data: { search: search_term },
success: function (ajaxresult) {
$("table-data").html(ajaxresult);
}
});
推荐阅读
- javascript - nodemailer日历活动邀请不起作用
- linux - 向变量添加特殊值
- android - 我的导航抽屉没有触发项目选择监听器
- javascript - 用javascript测试素数
- javascript - 将查找字段设置为仅显示联系人
- php - Php If 语句,从 CMB2 返回设置值
- java - XSL LookUp 打破了内部引用
- java - 将 ImageButton 充气后放置在 ConstraintLayout 中
- python - 使用 to_sql 将数据从 pandas 数据帧导入 SQL 数据库时 PC 挂起
- angular - Angular4+PrimeNG+DropDown 绑定