未捕获类型错误:无法读取属性';初始';提交表单时Javascript中未定义的
我正在尝试使用pythonweb.py模块制作一个社交网络迷你web应用程序。 我用html制作了一份注册表,但当我填写详细信息并提交时,浏览器控制台会显示以下输出:未捕获类型错误:无法读取属性';初始';提交表单时Javascript中未定义的,javascript,jquery,python-3.x,web.py,Javascript,Jquery,Python 3.x,Web.py,我正在尝试使用pythonweb.py模块制作一个社交网络迷你web应用程序。 我用html制作了一份注册表,但当我填写详细信息并提交时,浏览器控制台会显示以下输出: Uncaught TypeError: $(...).ready(...) is not a function at scripty.js:22 loaded jquery-3.4.1.min.js:2 Uncaught TypeError: Cannot read property 'init' of undefined at
Uncaught TypeError: $(...).ready(...) is not a function
at scripty.js:22
loaded
jquery-3.4.1.min.js:2 Uncaught TypeError: Cannot read property 'init' of undefined
at HTMLDocument.<anonymous> (scripty.js:4)
at e (jquery-3.4.1.min.js:2)
at t (jquery-3.4.1.min.js:2)
下面是python中的controller.py文件代码
import web
from Models import RegisterModel
urls = (
'/', 'Home',
'/register', 'Register',
'/postregistration', 'PostRegistration'
)
render = web.template.render("Views/Templates", base="MainLayout")
app = web.application(urls, globals())
# Classes/Routes
# Each class will be controlling a route
class Home:
def GET(self):
return render.Home()
class Register:
def GET(self):
return render.Register()
class PostRegistration:
def POST(self):
data = web.input()
print(data.username)
reg_model = RegisterModel.RegisterModel.insert_user(data)
return data.username
if __name__=="__main__":
app.run()
单击“提交”后,它将打印
“已加载”,并在浏览器控制台上显示错误
但它也必须表现出来
“提交的表格”
任何帮助都是值得的。更改您显示的JS的最后一行: 从 到 这修复了您的第一个错误
。。。不是函数
对于第二个错误,这意味着
$。物料未定义。删除它(如果您没有使用material design),或者确保相应的插件可用。更改您显示的JS的最后一行:
从
到
这修复了您的第一个错误。。。不是函数
对于第二个错误,这意味着$。物料未定义。要么删除它(如果您没有使用material design),要么确保相应的插件可用。这是您的脚本,修复了结束行错误,删除了材料并添加了注释,解释了每行的功能
// Wait until the page has fully loaded before applying the script
$(document).ready(function () {
// Bind a function to the submit form
$(document).on("submit", "#register-form", function (e) {
// Prevent the default form post behavior to prevent the page from reloading
e.preventDefault();
// Get the form data
var form = $('#register-form').serialize();
// Send an ajax request over to the route /postregisteration
$.ajax({
url: '/postregisteration',
type: 'POST',
data: form,
success: function (response) {
console.log("form submitted");
console.log(response);
}
});
});
});
以下是您的脚本,其中结束行错误已修复,材料已删除,并添加了解释每行功能的注释
// Wait until the page has fully loaded before applying the script
$(document).ready(function () {
// Bind a function to the submit form
$(document).on("submit", "#register-form", function (e) {
// Prevent the default form post behavior to prevent the page from reloading
e.preventDefault();
// Get the form data
var form = $('#register-form').serialize();
// Send an ajax request over to the route /postregisteration
$.ajax({
url: '/postregisteration',
type: 'POST',
data: form,
success: function (response) {
console.log("form submitted");
console.log(response);
}
});
});
});
在代码中,您从对象$.material
调用了名为init
的函数,但似乎$.material
未定义。你必须了解你为什么要调用它,它是什么,等等。你忘记加载那个脚本了吗?你使用它吗?这里的问题与Python无关,是您的客户端javascript出现故障。实际上,我正在学习Python课程,而且我是JS新手,所以我只是复制了这个JS代码以从html表单获取数据。我搜索了整个项目,但没有找到“$material”。我不知道老师为什么要写,我想这是jquery的问题。使用web.py从python中的html表单获取数据还有其他方法吗?不要只是复制随机的JS代码;最后一行写着}()代码>导致第一个错误;将其更改为})代码>。接下来,删除$.material.init()代码>行,您不需要它。我通过复制新的文件/材质结构修复了它,它可以正常工作。在您的代码中,您正在从对象$调用名为init
的函数。material
但似乎$。material
未定义。你必须了解你为什么要调用它,它是什么,等等。你忘记加载那个脚本了吗?你使用它吗?这里的问题与Python无关,是您的客户端javascript出现故障。实际上,我正在学习Python课程,而且我是JS新手,所以我只是复制了这个JS代码以从html表单获取数据。我搜索了整个项目,但没有找到“$material”。我不知道老师为什么要写,我想这是jquery的问题。使用web.py从python中的html表单获取数据还有其他方法吗?不要只是复制随机的JS代码;最后一行写着}()代码>导致第一个错误;将其更改为})代码>。接下来,删除$.material.init()代码>行,你不需要它。我通过复制新的文件/材料结构来修复它,它可以工作。它们不应该是。这里有一个可行的办法(当然这里不存在“后注册”,所以ajax请求失败,但javascript代码是功能性的):是的,它现在已经修复了,谢谢,我在这里停留了一段时间。不应该这样。这里有一个可行的办法(当然这里不存在“后注册”,所以ajax请求失败,但javascript代码是功能性的):是的,现在已经修复了,谢谢,我在这里停留了一段时间。
});
// Wait until the page has fully loaded before applying the script
$(document).ready(function () {
// Bind a function to the submit form
$(document).on("submit", "#register-form", function (e) {
// Prevent the default form post behavior to prevent the page from reloading
e.preventDefault();
// Get the form data
var form = $('#register-form').serialize();
// Send an ajax request over to the route /postregisteration
$.ajax({
url: '/postregisteration',
type: 'POST',
data: form,
success: function (response) {
console.log("form submitted");
console.log(response);
}
});
});
});