[英]Form population and validation using AJAX calls
Update: I figured out how to populate the form with default data. 更新:我想出了如何用默认数据填充表单。 How would I go about populating error messages when the data entered is invalid (when Submit is clicked)?
当输入的数据无效时(单击“提交”时),如何处理错误消息?
In line 5 you have forgotten a (
. This block's line: 在第5行中,您忘记了
(
.。
$(document).ready(function() {
$("#InsertDefault").click(function() {
$.ajax{url: "backend.php?act=default", success: function(result) {
console.log($.parseJSON(result));
data = $.parseJSON(result);
document.getElementById("name").value = data["name"];
});
This: 这个:
$.ajax{url: "backend.php?act=default", success: function(result) { //...
Should be: 应该:
$.ajax({url: "backend.php?act=default", success: function(result) { //...
// ↑
You have to write your ajax call like below.. As Nitai Pointed out you missed '(' before ajax. 您必须像下面这样编写ajax调用。.正如Nitai指出的那样,您在ajax之前错过了'('。
Also look for other closing brackets also as i can see they look suspicious in your program. 也请寻找其他右括号,因为我发现它们在您的程序中看起来可疑。
$(document).ready(function() {
$("#InsertDefault").click(function() {
$.ajax({url: "backend.php?act=default", success: function(result) {
console.log($.parseJSON(result));
data = $.parseJSON(result);
document.getElementById("name").value = data["name"];
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.