I am trying to make an Ajax call to my server by clicking href. When my href is clicked, I successfully go to my server and invoke a specific route. My route serves me correctly and sends me data. Below is a script that does this.
$('.graph-switch').click(function (){ event.preventDefault(); $.getScript("js/ejs_production.js", function() $.ajax({ url:'/spiderSwitch', type: 'GET', data: { type: $(this).attr('href') }, success: function(result){ console.log(result);
At this point, I need to redisplay the part I want to change. Below is the HTML part that I want to change.
<div class="panel-body text-center"><% include partials/spider-chart.ejs %> </div>
I basically add the spider-chart.ejs file using the ejs include keyword. Below is the spider-chart.ejs file.
<script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/highcharts-more.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> <div id="chart" style="min-width: 300px; max-width: 1000px; height: 300px; margin: 0 auto"></div> <script> var spiderGraphData = <%- JSON.stringify(spiderGraphData) %> var options = { metric: 'accuracy' } console.log(JSON.stringify(spiderGraphData)); SpiderChartControl.draw("chart", spiderGraphData, options); </script>
This is basically a script that populates a div using a library with tall charts. As I understand it, there are two approaches that I could not follow.
something like that:
$("#id").innerHtml = "<div class='panel-body text-center'> <% include partials/spider-graph.ejs %> </div>";
or something like this using ejs constructs:
new EJS({url : 'partials/spider-chart.ejs' }).update('.tab-pane active', result);
I do not have much hope for this question, but there is no answer to this specific problem on any web resource.