简体   繁体   English

使用JS文件的Web.py问题

[英]Web.py trouble using JS file

I am following a tutorial for the web.py framework, and I am basically setting up the framework for a blog. 我正在遵循有关web.py框架的教程,并且基本上是在为博客设置框架。 However, when I implement the registration form, I use a js file that was provided to me by the teacher of the online class. 但是,当我执行注册表时,我使用的是在线课程老师提供给我的js文件。 It is the following: 如下:

$(document).ready(function(){
console.log("loaded");
$.material.init();

$(document).on("submit", "#register-form", function(e){
    e.preventDefault();
    console.log("form submitted");
    var form = $('#register-form').serialize();
    $.ajax({
        url: '/postregistration'
        type: 'POST'
        data: form
        success: function(response){
            console.log(response);
        }
    });
});

}); });

Inside of the HTML file, I define it as follows, along with the rest of my js files: 在HTML文件中,我将其定义如下,并将其与其他js文件一起:

$var js: static/js/jquery-3.2.1.min.js static/js/bootstrap.min.js static/js/material.min.js static/js/ripples.min.js static/js/scripty.js

scripty.js is located in static/js, so I believe my syntax is all right, however I do not get any feedback from the console in Chrome when I access the website through localhost. scripty.js位于static / js中,因此我认为我的语法还可以,但是当我通过localhost访问网站时,我没有从Chrome控制台获得任何反馈。 This is a problem since I want to use AJAX to get the information, but I can't tell if the js is working. 这是一个问题,因为我想使用AJAX来获取信息,但是我无法确定js是否有效。 Can anyone help me figure out what's wrong? 谁能帮助我找出问题所在? Thanks! 谢谢!

$var js simply defines a parameter named js . $var js只是定义了一个名为js的参数。 It doesn't actually tell the browser to load javascript -- in fact, by itself, it doesn't tell the browser anything. 它实际上并没有告诉浏览器加载javascript,实际上,它本身并没有告诉浏览器任何信息。

You'll need to write the appropriate HTML in your template: 您需要在模板中编写适当的HTML:

<script src="/static/js/jquery...."></script>
<script src="/static/js/bootst...."></script>

etc. 等等

If you want to utilize your $js , you could have your template write the loads for you: 如果您想利用$js ,可以让您的模板为您编写负载:

$if content.get('js', None):
    $for x in content.js.split(' '):
        <script src="/$x"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM