点击我的aspx页面上的一个按钮,我正在生成一个.csv文件,可以在javascript dygraph中使用:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table width="1024" align="center" cellpadding="0" cellspacing="0" border="0" class="wrapper">
<tbody>
<tr>
<td width="1024" class="wrapper">
<table width="25%" align="left" cellpadding="0" cellspacing="0" border="0" class="series">
<tbody>
<tr>
<td align="center">
<a target="_blank" class="editorLinks tooltip" style="color: #000000; text-decoration: none;">
<div>
<img src="../../car_2series.jpg" width="90" height="44" alt="2 Series" border="0" style="display: block;">
</div>
<h3 style="margin: 15px 0 45px; margin-top: 15px; margin-bottom: 45px; color: #030000;
font-family: Helvetica,Arial,sans-serif; font-size: 0.9em;">
Car A</h3>
</a>
</td>
</tr>
</tbody>
</table>
<table width="25%" align="left" cellpadding="0" cellspacing="0" border="0" class="series">
<tbody>
<tr>
<td align="center">
<a target="_blank" class="editorLinks tooltip" style="color: #000000; text-decoration: none;">
<div>
<img src="../../../feb2015/car_4series.jpg" width="90" height="44" alt="4 Series" border="0" style="display: block;">
</div>
<h3 style="margin: 15px 0 45px; margin-top: 15px; margin-bottom: 45px; color: #030000;
font-family: Helvetica,Arial,sans-serif; font-size: 0.9em;">
Car B</h3>
</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table width="1024" align="center" cellpadding="0" cellspacing="0" border="0" class="wrapper">
<tbody>
<tr>
<td width="1024" class="wrapper">
<table width="25%" align="left" cellpadding="0" cellspacing="0" border="0" class="series">
<tbody>
<tr>
<td align="center">
<a target="_blank" class="editorLinks tooltip" style="color: #000000; text-decoration: none;">
<div>
<img src="../../car_6series.jpg" width="90" height="44" alt="6 Series" border="0" style="display: block;">
</div>
<h3 style="margin: 15px 0 45px; margin-top: 15px; margin-bottom: 45px; color: #030000;
font-family: Helvetica,Arial,sans-serif; font-size: 0.9em;">
Car B</h3>
</a>
</td>
</tr>
</tbody>
</table>
<table width="25%" align="left" cellpadding="0" cellspacing="0" border="0" class="series">
<tbody>
<tr>
<td align="center">
<a target="_blank" class="editorLinks tooltip" style="color: #000000; text-decoration: none;" data-title="1/100%">
<div>
<img src="../../../car_7series.jpg" width="90" height="44" alt="7 Series" border="0" style="display: block;">
</div>
<h3 style="margin: 15px 0 45px; margin-top: 15px; margin-bottom: 45px; color: #030000;
font-family: Helvetica,Arial,sans-serif; font-size: 0.9em;">
7 Series</h3>
</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
稍后同样在同一个按钮点击事件中,我使用.csv作为源代码填写dygraph的javascript代码填充div容器(在protected void btn_start_Click(object sender, EventArgs e)
{
.....
System.IO.File.WriteAllText(MapPath("~/Data/") + authuser + "_data.csv", data);
上为空):
Page_Load
一切正常但有旧数据。例如,我第一次打开页面时,生成带有数据的.csv两周,dygraph保持为空。然后我在页面上生成数据3周,然后我会显示带有2周数据的dygraph。所以它始终采用旧数据。
那么我怎么能告诉javascript始终采用新生成的.csv而不是以前的会话中的旧的.csv?也尝试protected void btn_start_Click(object sender, EventArgs e)
{
.....
System.IO.File.WriteAllText(MapPath("~/Data/") + authuser + "_data.csv", data);
.....
string strDiagram = @"<script type=""text/javascript"">
chart = new Dygraph(document.getElementById(""MainContent_DivDiagramm""), 'http://webserver/test/Data/" + authuser + @"_data.csv',... //String reduced here
.....
DivDiagramm.InnerHtml = strDiagram;
,但结果相同。谢谢!
答案 0 :(得分:1)
在JavaScript中访问CSV文件网址时,将某种版本控制查询字符串添加到其中,例如:
chart = new Dygraph(
document.getElementById(""MainContent_DivDiagramm""),
'http://webserver/test/Data/" + authuser + @"_data.csv?v=" + DateTime.Now.Ticks.ToString() + "');"