[英]how to read file from a path which is in text area in jquery
i want to read the file whose path comes dynamically and stores in the text area how to read that file from text area. 我想读取路径动态变化的文件并将其存储在文本区域中,如何从文本区域读取该文件。 so far i have made this but it still doesnot work.
到目前为止,我已经做到了,但仍然无法正常工作。
Below is my code. 下面是我的代码。
google.load("visualization", "1", {packages:["corechart", "charteditor"]});
$(function(){
$("#csv").bind("change", function(event){
var reader = new FileReader();
reader.onload = function(theFile) {
try {
alert(theFile.target.result);
var input = $.csv.toArrays(theFile.target.result);
}
catch(e) {
alert("CSV Parse error.");
return;
}
$("#output").pivotUI( input, {
renderers: $.extend(
$.pivotUtilities.renderers,
$.pivotUtilities.gchart_renderers,
$.pivotUtilities.d3_renderers
)
});
};
reader.readAsText(event.target.files[0]);
});
});
<% String d=request.getParameter("DP")!=null?request.getParameter("DP").toString():"";
System.out.println(d);
%>
<p>
<input type="text" id="csv" value="<%=d%>">
<div id="output" style="margin: 10px;">
</div>
I don't think tou can read data from a file in jQuery / JavaScript directly. 我认为tou不能直接从jQuery / JavaScript中的文件读取数据。
A better way is to deal with the server side to provide data in JSON or something like that. 更好的方法是处理服务器端以JSON或类似方式提供数据。
Check this site for more help about JSON: JSON Example 检查此站点以获取有关JSON的更多帮助: JSON示例
Here is the code for reading the text file using jquery: 这是使用jquery读取文本文件的代码:
var value='';
var pathOffile=''; ( here you can dynamically pass the path )
$.get(pathOffile, function( data ) {
value=data;
alert('reading text value: '+value);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.