简体   繁体   English

未捕获的SyntaxError:意外的令牌多个表单函数

[英]Uncaught SyntaxError: Unexpected token multiple form functions

I added the following submit function to my .js file: 我将以下提交函数添加到我的.js文件中:

$( "form" ).on( "submit", function( event ) {


event.preventDefault();

  var data = $( this ).serialize();
         $.ajax({
            type: "POST",
            url: "content/rev/a_submit.php",
            data: "data=" + data,
            console.log(data);
            success: function(result){
                $("#acct_content").html(result);
             }
        });
});

When doing that I got this error upon page load: 这样做时我在页面加载时遇到此错误:

"Uncaught SyntaxError: Unexpected token . " “Uncaught SyntaxError:意外的令牌。”

The function worked though, When I hit submit it submits the data I'd expect it to. 该功能虽然有效,但当我点击提交时,它会提交我期望的数据。

But, It prevents these 2 other form functions from not working: 但是,它阻止这两个其他表单函数不起作用:

$("form").ready(function() {
    var sap = $(this).attr('id');

    forecast_calc(sap);

});

and

$("form").change(function() {
    var sap = $(this).attr('id');

    forecast_calc(sap);

});

If I comment out the submit function everything works fine. 如果我注释掉提交功能,一切正常。

Kind of lost/frustrated here. 在这里有点失落/沮丧。

Thanks, 谢谢,

Object literals , like the one passed to $.ajax() , don't allow for statements to be included directly under them. 对象文字 ,如传递给$.ajax() 文字 ,不允许将语句直接包含在它们之下。

The console.log(data); console.log(data); just needs to be separated from it: 只需要与它分开:

var data = $( this ).serialize();

console.log(data);

$.ajax({
    // ...
});

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

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