2016-07-14 6 views
0

ボタンをクリックしていくつかの検証後にリダイレクトするページを取得する際に問題が発生しました。私は複数のsoluitonsを試して、アドレスバーがURLを移入するが、リダイレクトは同じ結果に取得し続ける。私がf5でリフレッシュしたり、ブラウザのリフレッシュボタンをクリックして動作し、ページがリダイレクトされて正常に読み込まれた場合これは私が試したすべてのブラウザ上にあります。だから、私は何かを逃しているか、間違っていなければならない以下の私のコードです:JSページのリダイレクトが実行されない


  ........ 
      .............. 
      //render function for json + templates like handlebars, xml + xslt etc. 
      render: function (dataItem, statuses) { 
       $list.html(template(dataItem.content)); 
       // action button events 
       //$('.action a').on("click",function (e){ 
       $('.action a').bind('click', function(e){ 
        var $this = $(this), 
         action = $this.attr("action"), 
         $id = $this.closest('ul').attr('id'); 
        // get which link was click for appropriate action 
        switch(action){ 
         case 'prev' : 

         break;; 

         case 'edit' : 
          if($this.hasClass("actionEnabled")) { 
           $().ajaxCall(checkURL,{'ID':$id}) 
           .done(function(data){ 
            if(data.result == 0) { 
             var baseURL = window.location.href.replace(window.location.hash, '') + '#', 
              url = baseURL + secondUrl_part + "?ID=" + $id; 
              // url = "http://mysite/index.php#/page/destPage.php?ID=idabcdefgh" 

             // tried with javascript all these different methods -> still did not work 
             // method 1 
             $(location).attr('href', "http://mysite/index.php#/page/destPage.php?ID=idabcdefgh"); 
             // method 2 
             window.location = "http://mysite/index.php#/page/destPage.php?ID=idabcdefgh"; 
             // method 3 
             window.location.href = "http://mysite/index.php#/page/destPage.php?ID=idabcdefgh"; 
             // method 4 
             window.location.replace("http://mysite/index.php#/page/destPage.php?ID=idabcdefgh"); 

             // even tried with return false as suggested by some people 
             //return false; 

            } else { 
             // todo error message no longer exist 
            } 
           }) 
           .fail(function(){ 
            // todo error : could not be loaded 
           }) 
          } else { 
           e.preventDefault(); 
           // to do add message cannot edit 
          } 
         break;; 

         case 'del' : 

         break; 
        } 

       }); 
      } 
      .......... 
      ....... 
      ..... 
+0

に基づいてコードがなぜあなたは 'php'タグでこの質問をマークしたのでしょうか? – FirstOne

+0

これは、ページF5をリロードすると機能しますか? –

+0

@イワン・カラマン:はい、私はF5を押すとロードします。 @FirstOne:私はphpページにリダイレクトしようとしているので、PHPを追加しました。違いがあるかどうかはわかりません。 – boulepick

答えて

0

ここでイワンの答え

  //render function for json + templates like handlebars, xml + xslt etc. 
     render: function (dataItem, statuses) { 
      $list.html(template(dataItem.content)); 
      // action button events 
      //$('.action a').on("click",function (e){ 
      $('.action a').bind('click', function(e){ 
       var $this = $(this), 
        action = $this.attr("action"), 
        $id = $this.closest('ul').attr('id'); 
       // get which link was click for appropriate action 
       switch(action){ 
        case 'prev' : 

        break;; 

        case 'edit' : 
         if($this.hasClass("actionEnabled")) { 
          $().ajaxCall(checkURL,{'ID':$id}) 
          .done(function(data){ 
           if(data.result == 0) { 
            var baseURL = window.location.href.replace(window.location.hash, '') + '#', 
             url = baseURL + secondUrl_part + "?ID=" + $id; 
            $(location).attr('href', url); 
            location.reload(); 
           } else { 
            // todo error message no longer exist 
           } 
          }) 
          .fail(function(){ 
           // todo error : could not be loaded 
          }) 
         } else { 
          e.preventDefault(); 
          // to do add message cannot edit 
         } 
        break;; 

        case 'del' : 

        break; 
       } 

      }); 
     } 
関連する問題