使用iframe嵌入csv并允许用户从中进行搜索 [英] Use Iframe to embed csv and allow user to search from it

查看:116
本文介绍了使用iframe嵌入csv并允许用户从中进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这里有一个简单的html / jscript代码,允许用户输入一个关键字并将样本csv数据(在此代码中模拟为var​​ CSV)的结果返回到HTML格式的表格格式,现在我希望使用iframe嵌入CSV而不是将我的数据库引用到此模拟CSV,我该怎么做?
此代码工作正常,但我需要将我的搜索数据库引用到iframe。
提前感谢您。

I have a simple html/jscript code here which allow users to enter a keyword and return result from sample csv data (simulated as var CSV in this code) to table format in HTML, now I wish to use the iframe where the CSV is embedded instead of referring my DB to this simulated CSV, how can I do that? This code is working fine but I need to refer my search database to iframe. Thank you in advance.

<html>
<head>
    <title>CSV Database</title>
    <script type="text/javascript">
        /* Following is a SIMULATED CSV file only.*/
        var CSV =  'APRIL,RED,HAPPY,TEACHER,092236015\n';
        CSV += 'BRIAN,YELLOW,SAD,ENGINEER,092236015\n';
        CSV += 'JIMBOY,BLUE,CRAZY,PROGRAMMER,092236015\n';
        CSV += 'JAYCEE,GREEN,MOODY,MAKE-UP_ARTIST,092236015\n';
        CSV += 'GALLIE,BLACK,SERIOUS,CYCLIST,092236015\n';
    </script>

</head>
<body onload="MakeDB()">
    Keyword: <input type="text" value="" id="ERP">
    <input type="button" value="Search"   onclick="CSVsearch(document.getElementById('ERP').value)">
    <p>
    <div id="tblDisplay"></div>
    <script type="text/javascript">

        var DB = new Array();
        function MakeDB() { DB = CSV.split('\n'); }

        function CSVsearch(dbInfo) {
            var posn = -1;
            for (i=0; i<DB.length; i++) {
                tmp = DB[i];
                if (tmp.indexOf(dbInfo) != -1) { posn = i; break; } 
            }
            if (posn == -1) { alert('No matching result from the file'); }
            else { document.getElementById('tblDisplay').innerHTML =    displayAsTable(DB[posn]); }
        }

        function displayAsTable(info) {
            var str = '<table border="1" width="35%">';
            var ary = info.split(',');
            str += '<tr><th>KEYWORD</th><th>INFO1</th><th>INFO2</th><th>INFO3</th><th>INFO4</th></tr>';
            str += '<tr><td>'+ary.join('</td><td>')+'</td></tr>';
            str += '</table>';
            return str;
        }
    </script>
    <br>
    <br>
    <br>
    <br>
    <br>
    <iframe src="file:///C:/Users/april_ibanga/Desktop/data.txt" name="data" frameborder="1" scrolling="auto" width="700" height="300" align="bottom"></iframe> 
</body>
</html>


推荐答案

据我所知,你无法加载只是iframe中的任何东西并刮掉它。 Javascript通常是frameVar.contentWindow,但当我尝试将src作为txt或csv文件时,这是null。

From what I can tell, you can't load just anything in an iframe and scrape it. The Javascript normally would be frameVar.contentWindow, but this is null when I attempt it with the src being a txt or csv file.

Web应用程序通常通过Web服务处理此问题调用返回表示序列化文件内容的html,xml,json响应。

Web applications usually handle this via web service calls that return html,xml,json responses that represent the serialized file contents.

祝你好运!

这篇关于使用iframe嵌入csv并允许用户从中进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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