2012-09-07 2 views
0

JS 함수에 리디렉션 URL 링크 (예 : form.php에 대한 양식 액션)를 아래 코드에 추가하려면 어떻게해야합니까? 다른 방법으로 코드를 시도했지만 여전히 작동하지 않습니다. 자바 스크립트 안에 PHP 코드로리디렉션 URL 링크를 JS 함수에 추가하십시오.

$(document).ready(function() 
{ 

    <?php 
     someFunction(); 
    ?> 
}); 

하지만이 파손

$(document).ready(function() { 
    $("#submit_butt").click(function() { 
     var conf = { 
      frequency: 5000, 
      spread: 5, 
      duration: 600 
     }; 
     /* do your AJAX call and processing here... 
     .... 
     .... 
     */ 
     // this is the call we make when the AJAX callback function indicates a login failure 
     $("#login").vibrate(conf); 

     // let's also display a notification 
     if($("#errormsg").text() == "") 
      $("#loginform").append('<p id="errormsg">Invalid username or password!</p>');  

     // clear the fields to discourage brute forcing :) 
     $("#password").val(""); 
     document.forms['login_form'].elements['username'].focus(); 
    }); 
}); 
+1

php는 서버에서 작동합니다. js는 클라이언트에서 작동합니다. js 코드에 php 함수를 추가 할 수 없습니다. – zerkms

+0

죄송합니다. JS 함수에 리디렉션 URL을 추가하는 방법을 알려드립니다. 내 게시물을 수정했습니다. 죄송합니다. –

+2

'window.location.replace ('http://google.com');'--- 이것은 js에서 리디렉션하는 방법입니다. – zerkms

답변

2

당신이

// similar behavior as an HTTP redirect 
window.location.replace("http://stackoverflow.com"); 

// similar behavior as clicking on a link 
window.location.href = "http://stackoverflow.com"; 

https://developer.mozilla.org/en-US/docs/DOM/window.location

참조를 시도 할 수 있습니다에 .php하는 경우 : How to redirect to another webpage in JavaScript/jQuery?

+0

좋은 .. 공유 주셔서 감사합니다. –

+0

방금 ​​다른 사람의 대답을 그대로 받아들였습니까? http://stackoverflow.com/a/506004/251311 – zerkms

+0

@zerkms : 예. 물론이지만 링크를 언급하는 것을 잊어 버렸습니다. –

-2

당신이 할 수있는 단지가 PHP에 의해 처리 될 수 있도록 자바 스크립트 PHP 파일에있는 경우. 그래서 변경해야합니다은 .js 파일에 링크는

+0

다른 것들 사이에는 많은 구문 오류가 있습니다. – Marty

0

시도 할 수

<script> 
function name(){ 
    window.location ='abc.php'; 
} 
</script> 
1

사용할 수 있습니다 ..

window.location.href = "http://www.google.com";