0

我需要将 XML 内容从 XML 文件读取到 HTML。

HTML:

<input type="file" id="fileImport" name="fileImport" />

Javascript:

        $("#fileImport").change(function () {
            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }
            else {// code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            var src = $("#fileImport").val();

            xmlhttp.open("GET", src, false);
            xmlhttp.send();
            xmlText = xmlhttp.response;
            alert(xmlText);
        });

但是,例如,如果用户选择c:/q/r/ff.xml我得到的文件C:\fakepath\ff.xml.

4

0 回答 0