我如何添加PHP或JavaScript代码以从下拉菜单中选择新URL

时间:2018-02-05 16:41:41

标签: javascript php jquery html

我为两页写了这段代码

第一页是index.php,第二页是load.php。   index.php加载第二页load.php并每4秒更新一次数据的主要功能来自$ url。

两页工作正常,现在我需要使用(下拉菜单)添加其他代码,以允许选择不同的网址购买更改变量$ url。 我厌倦了添加提交表单,但是$ url变量没有执行该值。 有关添加此代码的任何帮助?

的index.php

<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script>$(document).ready(function(){
setInterval(function(){
    $("#screen").load('load.php')
}, 4000);});</script><div id="screen"></div>

和页面load.php

   <html>
    <style>

    table, th, td {
        border: 1px solid black;
    }
        tr:nth-child(even){
            background-color: #dddddd
        }
    </style>
<body>
<?php
$url="https://www.bitstamp.net/api/v2/ticker/bchusd";
$fgc = file_get_contents($url);
$json = json_decode($fgc,TRUE);
$bid=$json["bid"];
$ask=$json["ask"];
echo '<table>
       <tr><th>Company</th><th>Bid</th><th>Ask</th></tr>
       <tr><td>Bitstamp(USD)</td><td>'.$bid.'</td><td>'.$ask.'</td></tr>     
    </table>';
?>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您需要将$ .load更改为$ .post或$ .ajax并将url作为load.php的参数传递以收集例如$ _POST ['url']

在更改之后,您需要在javascript回调中进行更多操作,将新的html添加到#screen元素,例如$('#screen')。html(repsonse.html);

https://api.jquery.com/jquery.post/ https://api.jquery.com/jquery.ajax/