未定义的索引:处理此 AJAX 代码时的名称

Undefined Index : name while processing this AJAX Code

本文关键字:代码 AJAX 索引 处理 未定义      更新时间:2023-09-26
$(document).ready(function(){
    $('#add').click(function (e) {
        e.preventDefault();
        var inputdata = $('#iname').val();
        $.ajax({
            type: "POST",
            url: "get.php",
            data: inputdata,
            success: function (data) {
                alert("data" + data)
            }
        });
    });
});

此代码显示错误未定义的索引 : 名称。这是我的表单方法。 加 这是获取.php代码:

<?php
    $name = $_POST['name'];
    echo $name;
?>

你必须在数据变量对象名称中设置键和值:输入数据

$(document).ready(function(){
    $('#add').click(function (e) {
        e.preventDefault();
        var inputdata = $('#iname').val();
        $.ajax({
            type: "POST",
            url: "get.php",
            data: {
                name : inputdata
            },
            success: function (data) {
            alert("data" + data)
            }
        });
    });
});

最后,我找到了解决方案,但不是由于.htaccess文件的原因。 我已经创建了。 在我的应用程序中删除文件后工作正常,没有任何问题.. 我不知道为什么会发生这种情况,如果你知道请解决这个问题

#Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}'s([^.]+)'.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]
#error documment..
Options -Indexes
ErrorDocument 403 http://localhost/error/403