gpt4 book ai didi

php - 无法执行
标记中指定的操作

转载 作者:可可西里 更新时间:2023-10-31 23:29:17 24 4
gpt4 key购买 nike

我正在使用 jquery 来执行一个 php 文件,但问题是在执行 php 文件后它没有执行 <form> 中指定的“操作”标签...请帮我解决这个问题!如有错误请见谅。

这是 .js 文件

$(document).ready(function(){

//execute's the function on click
$("#submit").click(function(e){

/*jquery to call the url requested
and parse the data in json*/
$.ajax({
url: "register.php",
type: "POST",
data: {
fname: $("#fname").val(),
lname: $("#lname").val(),
email: $("#email").val(),
password: $("#password").val(),
mobile: $("#mobile").val()
},
dataType: "JSON",
/*Give out the alert box
to display the results*/
success: function (json){
if(json.error){
alert(json.error_msg);
e.preventDefault();
}else{
alert("Registeration successful!",json.user.email);
}
},
error: function(jqXHR, textStatus, errorThrown){
alert(errorThrown);
e.preventDefault();
}
});
});

});

这里是 .html 文件

    <html>
<head>
<title>jQuery Test</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src = "register.js"></script>
</head>

<body>

<!--html body-->
<form name = "register" action = "login.html" id = "register" method = "POST">
<label>First name:</label>
<input type = text name = "fname" id = "fname" required>
<label>Last name:</label>
<input type = "text" name = "lname" id = "lname" required>
<label>E-mail:</label>
<input type = "email" name = "email" id = "email" required>
<label>Password</label>
<input type = "password" name = "password" id = "password" required>
<label>Mobile no:</label>
<input type = "number" name = "mobile" id = "mobile" required>
<input type="submit" value="Insert" name="submit" id = "submit">
</form>
<div id = "result" align = "right"></div>
</body>
</html>

最佳答案

去掉这一行

e.preventDefault();

如果你想防止错误提交,在ajax的错误部分添加那行,

error: function(jqXHR, textStatus, errorThrown){
alert(errorThrown);
e.preventDefault();//<--- add here so that on error, your form is not submitted.
}

关于php - 无法执行 <form> 标记中指定的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34194813/

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