如何显示api结果的纯文本(新手问题)



我对api完全陌生。我想显示输出的纯文本响应:

https://vurl.com/api.php?url=https://google.com

到我的网页HTML,但它不工作。

我代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$url = urlencode('https://google.com');
$api_url = 'vurl.com/api.php?url='.$url;
$arr_output = json_decode(file_get_contents($api_url), true);
document.write($arr_output);
</script>

感谢

不太确定为什么要将javascriptphp代码混合。然而,这是您应该遵循的方法:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
<?php
$url = urlencode("https://google.com");
$api_url = "vurl.com/api.php?url=".$url;
$arr_output = json_decode(file_get_contents($api_url), true);
echo $arr_output;
?>
</script>

相关内容

最新更新