[英]I am trying to send data to my PHP page from html page using ajax POST method but it give error ,Notice: Undefined index:
<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 page PHP页面
$search_input = $_POST["search"];
echo $search_input;
error错误
Notice: Undefined index: search in C:\xampp\htdocs\ajax\ajax-live-search.php on line 3
注意:未定义索引:在第 3 行搜索 C:\xampp\htdocs\ajax\ajax-live-search.php
Change "type" to "method" as below:将“类型”更改为“方法”,如下所示:
$.ajax({
url: "ajax-live-search.php",
method: "POST",
data: { search: search_term },
success: function (ajaxresult) {
$("table-data").html(ajaxresult);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.