gpt4 book ai didi

javascript - 无法从模态上的动态输入获取未定义或空引用的属性 'value'

转载 作者:行者123 更新时间:2023-12-03 06:34:24 25 4
gpt4 key购买 nike

我的模态打开并从运行良好的 AJAX 调用获取值,但随后我希望在按下“提交”按钮时将这些值发送回另一个 AJAX 调用,但是当我尝试从模态输入获取值时,我希望将这些值发送回另一个 AJAX 调用。我得到:无法获取未定义或空引用的属性“值”

我的按钮 HTML:

<button type="button" name="edit" class="btn btn-primary" id="user-submit" data-dismiss="modal">Submit</button>

我的脚本:

    <script>
$('#user-submit').on('click', function () {

var userID = document.getElementById(userID).value;
var dbpassword = document.getElementById(dbpassword).value;
var firstname = document.getElementById(firstname).value;
var lastname = document.getElementById(lastname).value;
var email = document.getElementById(email).value;
var phone = document.getElementById(phone).value;
var username = document.getElementById(username).value;
var password = document.getElementById(password).value;
var role = document.getElementById(role).value;

$.ajax
({
url: 'includes/updateuser.php',
type: 'POST', // send input data and use it inside PHP code using $_POST[''];
data: {userID: userID}, {dbpassword: dbpassword}, {firstname: firstname}, {lastname: lastname}, {email: email}, {phone: phone}, {username: username}, {password: password}, {role: role},
dataType: "text", //using json to populate the returned array.

success:function(updateuser) {
if(updateuser=="success")
{
alert("SUCCESS: User Updated Successfully!");
}
},

error:function(updateuser)
{
alert("ERROR: Please try again or call your Systems Administrator");
}

});

});
</script>

我做错了什么?任何帮助将不胜感激!谢谢!!!

enter image description here

最佳答案

Unable to get property 'value' of undefined or null reference

当 js 无法引用该元素时,就会出现问题。

在您的情况下,您很可能没有将userID(和其他ID)作为字符串传递。你可能需要这样做

document.getElementById('userID').value; // note the quotes

关于javascript - 无法从模态上的动态输入获取未定义或空引用的属性 'value',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38297988/

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