2014-09-06 9 views
0

몇 가지 이유로 제출 버튼의 기능을 변경하려고합니다. 제출 버튼을 클릭하여 호출되는 JS 함수를 호출 한 경우 어떻게 수동으로 html 태그에서 PHP 변수로 내 데이터를 보낼 수 있을지 모르겠다. 다음은 코드에 대한 간단한 설명입니다.html 태그에서 PHP로 데이터를 보내는 방법이 있습니까?

<html> 
<body> 
<input class="inputtext" id="email" name="email" type="text"></div> 
<input value="Submit" name="v4l" id="login" class="inputsubmit" type="button" onclick="myFunction();return false"> 
<script> 

function myFunction() { 
    var TestVar =document.getElementById("email").value; 
    document.write(TestVar); 
//store data of testvar to php 
} 

</script> 
<html> 
<body> 

나는 형식으로 할 수 있지만이 방법이 필요하다는 것을 알고있다.

+1

양식을 사용하거나 아약스 요청을해야합니다. –

+2

시작하기 https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started – GillesC

답변

0

jQuery에 익숙 하시길 바랍니다.

은 매우 간단

$("#login").click(function(){ 
     var email= $("#email").val(); 
     jQuery.post(
        "*your parsing url*", 
        {email:email}, 
        function(data){ 
         // Data returned from the ajax call 

        } 
       ) 
    }); 
0

jQuery 라이브러리이 만드는, 그리고 다른 많은 작업을 시도해보십시오

<html><head></head><body> 

<form id="myForm"> 
    <input class="inputtext" id="email" name="email" type="text"></div> 
    <input value="Submit" name="v4l" id="login" class="inputsubmit" type="button" onclick="myFunction();return false"> 
</form> 

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
<script> 
function myFunction() { 
    jQuery.ajax({ 
    url: 'yourcode.php', 
    type: 'POST', 
    data: jQuery('#myForm').serialize(), 
    success: function(response) { 
     alert('The data was sent, and the server said '+response); 
    } 
    }); 
} 
</script> 

</body></html> 

자세한 내용은 http://api.jquery.com/jquery.ajax/를 참조하십시오.

관련 문제