[英]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.