gpt4 book ai didi

php - 无法获取值(value)

转载 作者:行者123 更新时间:2023-12-02 19:30:24 24 4
gpt4 key购买 nike

这是我的ajax代码

//html

<input type="text" name="txtName" id="name_id" />

//测试.php

$.ajax(
{
url:"controller.php",
data:$('#txtName').val(),
success:
function(result){
alert(result);
}
}
);

//controller.php

<?php 

echo $_POST['txtName'];
?>

它给了我一个错误

Undefined index:txtName

最佳答案

使用参数名称

$.ajax(
{
type:'POST',
url:"controller.php",
data:"param1="+$('#txtName').val(),
success:
function(result){
alert(result);
}
}
);

以及 PHP

阅读方式

$_POST['param1'];
<小时/>

查看

关于php - 无法获取值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11561488/

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