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

<body>

<h1>点击按钮</h1>

<p>将创建一个带有 src 属性的 script 标签并将其放在文档中。</p>

<p>PHP 文件以 JSON 对象作为参数返回对函数的调用。</p>

<button onclick="clickButton()">单击我!</button>

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

<p>请尝试将 table 属性从“customers”更改为“products”。</p>

<script>
function clickButton() {
  var obj, s
  obj = { table: "customers", limit: 10 };
  s = document.createElement("script");
  s.src = "/static/demo/php/demo_php_jsonp_db.php?x=" + JSON.stringify(obj);
  document.body.appendChild(s);
}

function myFunc(myObj) {
  var x, txt = "";
  for (x in myObj) {
    txt += myObj[x].name + "<br>";
  }
  document.getElementById("demo").innerHTML = txt;
}
</script>

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