简体   繁体   English

未捕获到的SyntaxError:意外令牌:

[英]Uncaught SyntaxError: Unexpected token :

i have an unexpected token : but i dont know why this is. 我有一个意外的令牌:但是我不知道为什么。

the code where it is happening. 正在发生的代码。

<script type="text/javascript">
$('.delete-btn').click(function() {
 $.ajax(function() {
    type: 'POST',
    url: 'ajax.php',
    data: { filename: filename },
    success: function(return) {
        if(return == 'SUCCESS') {
            $this = $(this).closest('tr');
            $this.remove();
        }
    }
});
});
</script>

I hope someone can find why i get the unexpeded token : at the url: 'ajax.php', rule. 我希望有人能找到为什么我得到未过期的令牌:在URL:“ ajax.php”,规则。

The syntax error is in your success callback. 语法错误在您的success回调中。 You've named the argument return , which is a reserved word. 您已将参数return命名为保留字。 Call it something else. 叫别的东西。


Niet here, merging my answer into this one to complete the picture: Niet在这里,将我的答案合并到此图中以完成图片:

Change: 更改:

$.ajax(function() {

To: 至:

$.ajax({

Pay closer attention to what you're writing :p 密切注意您所写的内容:p

return is a reserved word in JavaScript. return是JavaScript中的保留字。 Use any other name other than return. 使用除return以外的任何其他名称。 I have used data instead of return. 我使用数据而不是返回。 Also there is type is an error in ajax function you have written. 您编写的ajax函数中也存在类型错误。 updated the same. 更新相同。 Use the below code 使用下面的代码

<script type="text/javascript">
$('.delete-btn').click(function() {
 $.ajax({
    type: 'POST',
    url: 'ajax.php',
    data: { filename: filename },
    success: function(data) {
        if(data == 'SUCCESS') {
            $this = $(this).closest('tr');
            $this.remove();
        }
    }
});
});
</script>

return is a keyword at javascript dont use it as a variable name return是javascript的关键字,请勿将其用作variable name

 <script type="text/javascript">
    $('.delete-btn').click(function() {
     $.ajax(function() {
        type: 'POST',
        url: 'ajax.php',
        data: { filename: filename },
        success: function(data) {
            if(data== 'SUCCESS') {
                $this = $(this).closest('tr');
                $this.remove();
            }
        }
    });
    });
    </script>

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

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