2014-05-18 4 views
0

텍스트 필드와 함께 다른 페이지로 보내려는 지정된 ID 번호가 포함 된 텍스트 양식이 있습니다. 그게 가능할까요?AJAX를 통해 텍스트 양식에서 다른 페이지로 다른 값 전달

<form name="cForm" id="cForm"> 
      Comment: <input type="textBox" name="cText" id="cText" /> 
      <input type="button" name="submitCreate" id="submitCreate" value="Create" onclick="showCreate('.$row['ID'].')" /><br> 
     </form> 

<script> 
function showCreate(str) { 
    if (str=="") { 
    document.getElementById("showCreate").innerHTML=""; 
    return; 
    } 
    if (window.XMLHttpRequest) { 
    // code for IE7+, Firefox, Chrome, Opera, Safari 
    xmlhttp=new XMLHttpRequest(); 
    } else { // code for IE6, IE5 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    xmlhttp.onreadystatechange=function() { 
    if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
     document.getElementById("showCreate").innerHTML=xmlhttp.responseText; 
    } 
    } 
    xmlhttp.open("Post","showCreate.php?q="+str,true); 
    xmlhttp.send(); 
} 
</script> 

내가 바로하지만이 시도 이해하도록

$comment = $_REQUEST["q"]; 
$ID = $_REQUEST["p"]; 

답변

1

확실하지 않은 별도의 변수에 텍스트 필드와 ID의 값을 좀하고 싶습니다 :

<form name="cForm" id="cForm"> 
      Comment: <input type="textBox" name="cText" id="cText" /> 
      <input type="button" name="submitCreate" id="submitCreate" value="Create" onclick="showCreate('.$row['ID'].')" /><br> 
     </form> 

<script> 
    function showCreate(str) { 
     if (str=="") { 
     $("#showCreate").html(""); 
     return; 
     } 
    $.ajax({ 
     type: "POST", 
     url: "showCreate.php", 
     data: "q="+str+"&p="+$("#cText").val() 
     }).done(function(result) { 
      $("#showCreate").html(result); 
     }); 
    } 
</script> 

그래서 당신은 원하는대로 PHP에서 vars를 사용할 수있게 될 것입니다

+0

안녕하세요 @volkinc 나는'Uncaught ReferenceError : s가이'' "="+ s + "& p ="+ $ ("# cText")에 대해 정의되어 있지 않습니다. 내부에? – user2691544

+0

죄송합니다. 그것은 오타입니다. s = str. 당신이 함수에 넘겨주는 전쟁 – volkinc

+0

이것은 정확하게 필요한 것입니다. 감사합니다 @ volkinc – user2691544

관련 문제