简体   繁体   English

我正在尝试使用 ajax POST 方法从 html 页面将数据发送到我的 PHP 页面,但它给出错误,注意:未定义索引:

[英]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.

相关问题 当我尝试从Ajax进行POST时PHP未定义的索引数据 - PHP Undefined index data when I try to POST from Ajax Ajax / PHP注意:未定义的索引: - Ajax / PHP Notice: Undefined index: 使用 ajax post 方法将数据发送到 php - send data to php using ajax post method 尝试使用ajax方法将javascript变量发布到php文件:POST,但在php文件中的$ POST数组中获取未定义的索引 - Trying to post a javascript variable to a php file using the ajax method : POST but getting an undefined index in $POST array within php file 如何在点击时将 html 和 ajax 的数据属性发送到 some.php 页面? - How can i send data attribute from html with ajax to some.php page, on click? I'm using AJAX to post an object from javascript to php within the same page and I'm getting the entire html page instead of the object - I'm using AJAX to post an object from javascript to php within the same page and I'm getting the entire html page instead of the object 我使用了ajax调用并发送“ itemShape”作为数据,但在URL页面中显示未定义的索引:itemShape - i used ajax call and send “itemShape” as data but in url page it's show Undefined index: itemShape 使用AJAX将PHP数据发布到另一个页面 - PHP POST data to another page using AJAX 使用ajax将数据发布到另一个php页面 - Post data to another php page using ajax 使用AJAX将表单数据发布到PHP页面 - Using AJAX to post form data to PHP page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM