如何从Java脚本中获取上载文件中的数据? [英] How Do I Get The Data From Upload File In Java Script?

查看:77
本文介绍了如何从Java脚本中获取上载文件中的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传像.txt这样的文件,我希望从中获取数据并存储在数组中并使用java脚本执行一些logoc

我的代码片段是

 function m1(file,target){
var file = document.getElementById(fup1)。value;

var input = file.trim()。replace(';',',')。split(',');
var distinctArray = input.filter(function(val){
return input.indexOf(val)== -1;
});
target.value = distinctArray.join(',');
}





我的控件是

<表> 
< tr>
< td> < asp:FileUpload ID = fup1 runat = server /> < / td >
< td>< asp:TextBox ID = txt1 runat = server TextMode = MultiLine> < / asp:TextBox > < / td >
< td>< input type = button id = btn1 value = 提交 onclick = ' m1(<%= fup1.ClientID%>,<%= txt1.ClientID%>);返回false;' /> < / td >
< / tr >
< / table > ;



这里我没有得到任何东西



请帮帮我。 ..谢谢提前

解决方案

读取上传的文件并不是那么简单。

文件控件的值只是文件名。



您需要访问实际的流。在HTML4中,唯一的方法是将包含文件输入的表单发布到服务器并让服务器读取文件。



幸运的是HTML5为您提供了方法通过javascript读取文件。但它并不像你希望的那么容易。请阅读;



http:// www。 html5rocks.com/en/tutorials/file/dndfiles/ [ ^ ]



我相信这篇博客文章会读取您需要的文本文件;



http://stackoverflow.com/ questions / 3146483 / html5-file-api-read-as-text-and-binary / 3146509#3146509 [ ^ ]



好运气!

I want to upload a file like .txt and i want to get the data from it and store in array and do some logoc in that by using java script
my snippet is

function m1(file,target) {
      var file = document.getElementById("fup1").value;

      var input= file.trim().replace(';', ',').split(',');
       var distinctArray = input.filter(function (val) {
           return input.indexOf(val) == -1;
           });
      target.value = distinctArray.join(',');
  }



and my controls are

<table>
   <tr>
   <td> <asp:FileUpload ID="fup1" runat="server" /></td>
   <td><asp:TextBox ID="txt1" runat="server" TextMode="MultiLine"></asp:TextBox></td>
   <td><input type="button" id="btn1" value="Submit" onclick='m1(<%=fup1.ClientID%>,<%=txt1.ClientID%>);return false;' /></td>
   </tr>
   </table>


Here i dont get any thing

please help me...thanks in advance

解决方案

Reading the uploaded file isn't that simple unfortunatly.
The value of the file control will just be the file name.

You'll need access to the actual stream. In HTML4 the only way to do this was to post a form containing the file input to the server and let the server read the file.

Luckily HTML5 gives you way's to read the file through javascript. But it isn't as easy a you hoped. Please read;

http://www.html5rocks.com/en/tutorials/file/dndfiles/[^]

And I believe this blog post reads a textfile like you need;

http://stackoverflow.com/questions/3146483/html5-file-api-read-as-text-and-binary/3146509#3146509[^]

Good luck!


这篇关于如何从Java脚本中获取上载文件中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆