2017-10-30 1 views
0

문제가 발생했습니다. 성공 후 내 기능이 리디렉션되지 않습니다. 리디렉션이없는 이유는 무엇입니까 ... if ... href after e.preventDefault(); 때때로 작동합니다.성공 후 URL로 Ajax 리디렉션

$('#nadwozie').change(function (e) { 
     if (window.confirm('Czy na pewno chcesz zmienić nadwozie/grafikę pojazdu ?')) { 
      var url = "raport_zapisanie_danepojazdu.php"; // the script where you handle the form input. 
      $.ajax({ 
       type: "POST", 
       url: url, 
       data: $("#FormRaport").serialize(), // serializes the form's elements. 
       dataType: "text", 
       success: function (data) { 
        window.location.href = "raport.php?id=" + <?php echo $raport[0]['id'];?> +"&nadwozie=" + $(this).val(); 
       }, 
       error: function (request, status, error) { 
        //alert(request.responseText + status + error); 
       } 
      }) 
      ; 
      e.preventDefault(); // avoid to execute the actual submit of the form. 
     } else { 
      $("#nadwozie").val(previous); 
      previous = $(this).val(); 
     } 
    }); 
+0

어쩌면 오류 처리기가 실행 중입니까? 나는 당신이'raport_zapisanie_danepojazdu.php'에 제출하는 정규 옛날 형식 대신에 왜 ajax를 사용하는지 모르겠다. 그러면 서버 측을'raport.php'로 재전송 할 수있다. – James

답변

0

당신은 대체 할 수

window.location.href = "raport.php?id=" + <?php echo $raport[0]['id'];?> +"&nadwozie=" + $(this).val(); 

로 :

window.location.assign("raport.php?id=" + <?php echo $raport[0]['id'];?> +"&nadwozie=" + $(this).val()); 

는 href가 단순히 URL을 반환하는 반면 실제로, 주어진 URL로 리디렉션() https://developer.mozilla.org/en-US/docs/Web/API/Location/assign

할당을 참조하십시오.

관련 문제