javascript ajax呼叫将我重定向到另一个URL

时间:2019-08-21 05:13:07

标签: javascript jquery ajax

我在用户登录后立即进行api调用,以获取通知总数,但是ajax调用将我重定向到ajax调用中提到的url,并在网页中显示整个json。并非每次都会出现此问题。有人可以帮我吗?

var notificationInterval = setInterval(getNotificationCount, 1000 * 60 * 1);
function getNotificationCount() {
    jq12.ajax({
    url: "/t/v1_getNotificationsCount.do",
    type: 'GET',
    dataType: 'json',
    success: function(response){
        if(response.isActiveUser == false){
            $('#h_profile_logout').children('.row-of-text-prof').trigger('click');
            return;
        }
        if(response.socialNotificationCount>0){
            if(jq12('#social-newsfeed-page:visible').length>0){
                var updatedDiscText = response.socialNotificationCount;
                if(response.socialNotificationCount>1){
                    updatedDiscText += " Updated discussions";
                }
                else{
                    updatedDiscText += " Updated discussion";
                }
                jq12('#updated-discussion-wrap').show();
                jq12('#updated-discussion-talk').html(updatedDiscText);
            }
            else{
                jq12('#social-notif-number-wrap').show();
                jq12('#social-notif-number').html(response.socialNotificationCount);    
            }

        }
        else{
            jq12('#social-notif-number-wrap').hide();
        }
        if(response.headerNotificationCountNew>0){
            jq12('#notification-number-wrap').show();
            jq12('#notification-number').html(response.headerNotificationCountNew);
        }
        else{
            jq12('#notification-number-wrap').hide();
        }
        if(response.calendarNotificationCount>0){
            jq12('#calendar-notif-number-wrap').show();
            jq12('#calendar-notif-number').html(response.calendarNotificationCount);
        }
        else{
            jq12('#calendar-notif-number-wrap').hide();
        }
    },
    error: function(){
        clearInterval(notificationInterval);
    }
  });
}

$(window).load(function(){
    if(window.location.pathname!="/social/v1_social.do"){
        setTimeout(function(){
            getNotificationCount();             
        },3000);
    }
});

0 个答案:

没有答案