繁体   English   中英

JS 错误未捕获 SyntaxError: Unexpected token if

[英]JS error uncaught SyntaxError: Unexpected token if

我已经编写了之前可以工作的代码,在网站上的其他一些其他详细信息之后,我的脚本停止工作。 我不确定我没有工作的原因。 我在控制台中收到以下错误:

Uncaught SyntaxError: Unexpected token if

代码 :

<script>
    $(document).on('click', '.btnsss', function(){
            var id = $(this).attr('data-id');
            var task = "fav";

            $.ajax(
               {
                  type:'GET',
                  url:'process.php',
                  context: this,
                  data: { "id": id, "task": task }
                  if(data === "4"){
                            window.location.href = '/prijava';
                        } else if(data === "1" || data === "2") {
                            alert('Doslo je do greske!');
                        } else {                  
                        success: function(data){
                        console.log(data);

                        $(this).addClass('active');
                        $(this).find('i').removeClass('glyphicon glyphicon-star-empty').addClass('glyphicon glyphicon-star');
                        $(this).removeClass('btn-success').addClass('btn-default');
                        $(this).removeClass('btnsss').addClass('btnrrr');

                        $.blockUI({ message: ' <center> <h1><span class="glyphicon glyphicon-th spin"></span></h1> <p> Ucitavanje. . .</p> </center> ' });  
                        setTimeout($.unblockUI, 500); 
                        }
                  }
               }
            );
    });
    </script>

我也是 js 的初学者,但我第一次解决了问题,并且在进行了一些其他编辑后所有这些脚本都停止了工作,有什么建议吗?

无效的 JavaScript。 if 语句就在对象声明的中间。 更像这样的东西可能对你有用,虽然我不完全确定你想要的最终结果是什么。

{
  type:'GET',
  url:'process.php',
  context: this,
  data: { "id": id, "task": task },
  success: function(data) {
    console.log(data);
    if(data === "4"){
        window.location.href = '/prijava';
    } else if(data === "1" || data === "2") {
        alert('Doslo je do greske!');
    } else { 
      $(this).addClass('active');
      $(this).find('i').removeClass('glyphicon glyphicon-star-empty').addClass('glyphicon glyphicon-star');
      $(this).removeClass('btn-success').addClass('btn-default');
      $(this).removeClass('btnsss').addClass('btnrrr');

      $.blockUI({ message: ' <center> <h1><span class="glyphicon glyphicon-th spin"></span></h1> <p> Ucitavanje. . .</p> </center> ' });  
      setTimeout($.unblockUI, 500); 
    }
  }
}

暂无
暂无

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

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