2016-11-07 16 views
0

上記のクエリの結果が真であるときにカウントダウン関数を呼び出すときに問題があります。基本的に、スクリプトは、ユーザーが権限を持っているかどうかをチェックし、権限がある場合はメッセージを表示し、カウントダウンして新しいページにリダイレクトします。私は、構文チェッカーを介してコードを実行し、それが有効に出てくる。条件が真のときに関数を呼び出す

しかし、ブラウザのデバッガの検査で、私は 'カウントダウン'のエラーが発生するのは不明です。私がここで間違っていることをはっきりとは分かりません。

function validate() { 
    var userName = $().SPServices.SPGetCurrentUser({ 
     fieldName: "UserName" 
    }); 
    var query = '<Query>' + 
     '<Where>' + 
     '<Eq>' + 
     '<FieldRef Name="userid" />' + 
     '<Value Type="User">' + userName + '</Value>' + 
     '</Eq>' + 
     '</Where>' + 
     '</Query>'; 

    $(document).ready(function() { 
     $().SPServices({ 

      operation: "GetListItems", 
      async: false, 
      listName: "test", 
      CAMLViewFields: "<ViewFields><FieldRef Name='userid' /></ViewFields>", 
      completefunc: function(xData, Status) { 

       var matchFound = false; //define flag 


       $(xData.responseXML).SPFilterNode("z:row").each(function() { 
        if (userName == $(this).attr("ows_userid")) { 
         matchFound = true; //set the flag to true indicating matched record 
        } 

        function countdown() { 

         var time_left = 5; 
         var cinterval; 
         var timestatus = 1; 
         var targetURL = "http://www.google.com" 

         function time_dec() { 
          time_left--; 
          document.getElementById('countdown').innerHTML = time_left; 
          if (time_left == 0) { 
           clearInterval(cinterval); 
           window.location = targetURL 
          } 
         } 

         function defaultstart() { 
          time_left = 5; 
          clearInterval(cinterval); 
          cinterval = setInterval('time_dec()', 1000); 
         } 

         defaultstart(); 
        } 
       }); 
       if (matchFound) 
        $('#validmsg').css('visibility', 'visible'); 

       else 
        $('#denymsg').css('visibility', 'visible'); 
       if (matchFound) { 
        countdown() 
       } 
      } 
     }); 
    }); 
} 
+0

どのエラーが参照されていますか? –

+0

@RScott次回は質問をしています。それはユーザーがそれをよりよく読むのを助けるでしょう。 – sam

+1

コードを書式設定した後、その答えは明らかです。それは範囲外です。常にコードを書式設定するか、この問題が常に発生します。 –

答えて

0

これは範囲外です。外側から呼び出す場合は、ループ外にcountdown()を定義する必要があります。私はそれを内部に置く必要がないのに加えて、あなたはxDataのいずれかを使用しているようではありません。

var matchFound = false; 
function countdown() { 
    var time_left = 5; 
    var cinterval; 
    var timestatus = 1; 
    var targetURL = "http://www.google.com" 

    function time_dec() { 
     time_left--; 
     document.getElementById('countdown').innerHTML = time_left; 
     if (time_left == 0) { 
      clearInterval(cinterval); 
      window.location = targetURL 
     } 
    } 

    function defaultstart() { 
     time_left = 5; 
     clearInterval(cinterval); 
     cinterval = setInterval('time_dec()', 1000); 
    } 

    defaultstart(); 
} 
$(xData.responseXML).SPFilterNode("z:row").each(function() { 
    if (userName == $(this).attr("ows_userid")) { 
     matchFound = true; //set the flag to true indicating matched record 
    } 
}); 
if (matchFound) { 
    $('#validmsg').css('visibility', 'visible'); 
    countdown(); 
} else { 
    $('#denymsg').css('visibility', 'visible');  
} 
関連する問題