首页 > 解决方案 > 如何在 php 页面中显示 javascript

问题描述

我将如何在 php 页面中显示此信息?我从我的广告供应商的 API 指南中获得了这个脚本。

谢谢!

   <html>
<head>
 <script type="text/javascript">

var request = require('request'); // npm package request
request.post(
'http://udmserve.com/udm/radalytics_api.cpx?action=report&api_key=xxx',
{ json: {"start_date":"2018-10-28","end_date":"2018-10-29", "columns":["paid_impressions","revenue"]} },
function (error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body)
    }
}
);
</script>
</head>

<body>
<h1>
  the rev is:
  <script type="text/javascript">
    document.write(request)
  </script>
</h1>
</body>
</html>

标签: javascriptphphtml

解决方案


如果要从 PHP 代码发送 POST 请求,可以使用Guzzle库。

首先,您应该使用Composer安装 Guzzle ,然后您可以轻松使用 Guzzle 并发送您的 POST 请求。

$client = new GuzzleHttp\Client();
$response = $client->post('http://udmserve.com/udm/radalytics_api.cpx?action=report&api_key=xxxx', [ 'json' => [
    'start_date' => '2016-08-02',
    'end_date' => '2016-08-03',
    'columns' => ["paid_impressions", "revenue"]
]]);

推荐阅读