1

I have a dropdown created with 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. 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.

<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.

6
  • did you do a console.log(this.responseText); to see what response you are getting? Commented Jul 29, 2019 at 13:03
  • do you have any error message on the console ? Commented Jul 29, 2019 at 13:03
  • I got no errors at all. The responseText i get is the Test.php code i showed you above. Commented Jul 29, 2019 at 13:11
  • And i am realy new to javascript, btw. Commented Jul 29, 2019 at 13:13
  • Are you sure that both files are in same directory??? Commented Jul 29, 2019 at 14:02

1 Answer 1

0

I think it will can help you https://www.w3schools.com/PHP/php_ajax_database.asp

If it will helpless, please show you PHP code.

If you want create dynamic page(php send you result of work), your php needs be on php server. And you can use simple solution(http://www.denwer.ru/).

Sign up to request clarification or add additional context in comments.

2 Comments

using the same code and loading php pages works fine. I have a php server set up on my computer as a test server. It is named .php at this moment only becuse i will add php at a later stage. Atm, i just whant the C3 graph to be showned.
Do I right undestand, that you can get data, but I want get data, when choose one of items? Maybe it can help you stackoverflow.com/questions/1535520/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.