2016-07-14 106 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

@ Ivan Karaman:是的,如果我打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; 
       } 

      }); 
     }