简体   繁体   English

从带有JavaScript的另一个页面加载带有javascript的页面

[英]Loading a page with javascript from another page with javascript

I have a dropdown created with javascript. 我有一个用javascript创建的下拉菜单。 When the user choose one of the items. 当用户选择其中一项时。 A seperate page will be loaded into the current page. 单独的页面将被加载到当前页面中。 The page i am trying to load uses a C3 graph, but the graph wont load on the first page. 我尝试加载的页面使用C3图,但是该图不会加载在第一页上。 But it will load by itself. 但是它将自行加载。

<script>
function Change_projection(str) {
  document.getElementById("chart_dis").innerHTML = "Laddar";
  var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("chart_dis").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET", "includes/Test.php", true);
        xmlhttp.send();
}
</script>
<div id="chart_dis"></div>

This is the Test.php, and it works fine on its own. 这是Test.php,它可以正常运行。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <link rel="stylesheet" href="/assets/vendor/libs/c3/c3.css">
    <div id="chart"></div>  
 <script type="text/javascript" >
 $(function() {
    var chart = c3.generate({
    bindto: '#chart',
    data: {
      columns: [
        ['data1', 30, 200, 100, 400, 150, 250],
        ['data2', 50, 20, 10, 40, 15, 25]
         ]
     }
    }); 
});
</script>
  <script src="/assets/vendor/libs/d3/d3.js"></script>
  <script src="/assets/vendor/libs/c3/c3.js"></script>

I whant to be able to load the graph when the user selects that option in the dropdown. 我希望当用户在下拉列表中选择该选项时能够加载图形。 The other options is for other information. 其他选项用于其他信息。

I think it will can help you https://www.w3schools.com/PHP/php_ajax_database.asp 我认为它将为您提供帮助https://www.w3schools.com/PHP/php_ajax_database.asp

If it will helpless, please show you PHP code. 如果无法解决问题,请向您显示PHP代码。

If you want create dynamic page(php send you result of work), your php needs be on php server. 如果您要创建动态页面(php将工作结果发送给您),则您的php需要在php服务器上。 And you can use simple solution( http://www.denwer.ru/ ). 您可以使用简单的解决方案( http://www.denwer.ru/ )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM