代码示例:(标识:eg_js_json_php_db_post)
<!DOCTYPE html>
<html>
<body>

<h1>使用 HTTP 方法 POST 把数据发送到 PHP 文件</h1>

<p id="demo"></p>


<script>
var xmlhttp, myObj, x, txt = "";
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    myObj = JSON.parse(this.responseText);
    for (x in myObj) {
      txt += myObj[x].CustomerId + "<br>";
    }
    document.getElementById("demo").innerHTML = txt;
  }
};
xmlhttp.open("POST", "/static/demo/php/demo_json_db.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send();
</script>

</body>
</html>
运行结果: