带回调函数的 JSONP 实例
- <!DOCTYPE html>
- <html>
- <body>
- <h1>请求调用函数</h1>
- <p>PHP 文件返回对您作为回调发送的函数的调用。</p>
- <button onclick="clickButton()">单击我!</button>
- <p id="demo"></p>
- <script>
- function clickButton() {
- var s = document.createElement("script");
- s.src = "demo_jsonp2.php?callback=myDisplayFunction";
- document.body.appendChild(s);
- }
- function myDisplayFunction(myObj) {
- document.getElementById("demo").innerHTML = myObj.name;
- }
- </script>
- </body>
- </html>