-1

重複の可能性:
JavaScript変数をPHPに渡す方法は?
javaScript変数をphp変数に送信します

ドキュメントにdocument.getElementById('name')フィールドがあり、その値はスクリプトによって変更されます。post(to server)を実行すると、document.getElementById('name')の現在の値を取得して設定します。それで

$temp= document.getElementById('name');
?>

psスクリプトコードがクライアント側とphpiサーバー側であることは知っていますが、この回避策が必要なので、助けてください。

4

2 に答える 2

2

あなたが持っている最良の選択肢はAJAX、値でリクエストを行うことだと思います。これにより、値を に送信して割り当てることができますPHP variables

それ以外の場合は、COOKIEetc を使用して値を一時的に保存し、サーバー側の関数が次に呼び出されるたびにサーバー側で使用できます。

Ajax コード

<script type='text/javascript'>
    function getXMLHTTPRequest() {
    try {
    req = new XMLHttpRequest();
    } catch(err1) {
      try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (err2) {
        try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (err3) {
          req = false;
        }
      }
    }
    return req;
    }



      var http = getXMLHTTPRequest();
       function sendValue() {
    var myurl = "session.php";  // to be present in the same folder
     var myurl1 = myurl;
    var value = document.getElementById('urDIV').value;
      myRand = parseInt(Math.random()*999999999999999);
      var modurl = myurl1+"?rand="+myRand+"url"+value ; // this will set the url to be sent

      http.open("GET", modurl, true);
      http.onreadystatechange = useHttpResponse;
      http.send(null);
    }


    function useHttpResponse() {
       if (http.readyState == 4) {
        if(http.status == 200) {
          var mytext = http.responseText;
          // I dont think u will like to do any thing with the response
          // Once you get the response, you are done.
            }
         }
         else {
             // don't do anything until any result is obtained
            }
        } 
</script>

HTML 部分

// considering you are calling on a button call

<input type='button' onclick='sendValue();'>
于 2012-10-10T12:07:57.947 に答える
0

データを含む新しいHTTPリクエストを作成します。

  • を生成し<form>て送信できます。
  • Ajaxを使用できます
  • location新しい値に設定できます
于 2012-10-10T12:06:59.197 に答える