将document.getElementById('name')中的var变量转换为php变量

将document.getElementById('name')中的var变量转换为php变量,php,javascript,Php,Javascript,可能重复: 我在一个文档中有document.getElementById'name'字段,它的值由脚本更改,当我向服务器发送邮件时,我希望获取文档的当前值。getElementById'name'并将其设置为 在 p、 我知道脚本代码是在客户端和php I服务器端,但我需要这种解决方法,因此请帮助..发出一个包含数据的新HTTP请求 您可以生成一个文件并提交它。 您可以使用Ajax 您可以将位置设置为新值 等 我认为最好的选择是使用这些值发出AJAX请求。有了它,您可以将值发送并分配给PHP

可能重复:

我在一个文档中有document.getElementById'name'字段,它的值由脚本更改,当我向服务器发送邮件时,我希望获取文档的当前值。getElementById'name'并将其设置为


p、 我知道脚本代码是在客户端和php I服务器端,但我需要这种解决方法,因此请帮助..

发出一个包含数据的新HTTP请求

您可以生成一个文件并提交它。 您可以使用Ajax 您可以将位置设置为新值 等
我认为最好的选择是使用这些值发出AJAX请求。有了它,您可以将值发送并分配给PHP变量

否则,您可以使用COOKIE等临时存储该值,然后在下次调用服务器端函数时在服务器端使用该值

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();'>

许多重复看到相关的侧边栏有没有什么特别的原因让你不直接贴上名字?我从哪里找不到,控件是引用了什么例子,怎么做?我是ajax新手!参考我的这个答案。它包含代码
// considering you are calling on a button call

<input type='button' onclick='sendValue();'>