Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
90 views
in Technique[技术] by (71.8m points)

javascript - Where can I store an XML file for the browser to read using ASP.Net MCV

I would like to have a xml file on my website that holds temporary information from a database. When I use VSCode to do so, it works just fine; but when I use my actual ASP.Net Web Application, it does not. I assume it has to do with the file path that I am using, any help would be greatly appreciated!

ASP.Net C#

string path = Server.MapPath("~/App_Data/phones.xml");
foreach (var pm in Model)
{
     // add each model to xml
}

JS

const MakePhoneOBJ = (xmlFile) => {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            xmlFunc(this);
        }
    };
    xmlhttp.open("GET", xmlFile, true);
    xmlhttp.send();
}

const xmlFunc = (xml) => {
    var xmlDoc = xml.responseXML;
    var root = xmlDoc.getElementsByTagName("Element");
    for (let i = 0; i < root.length; i++) {
        // Do something with the file contents
    }
}

HTML

<body onload="MakePhoneOBJ('@path');">
</body>
question from:https://stackoverflow.com/questions/66067458/where-can-i-store-an-xml-file-for-the-browser-to-read-using-asp-net-mcv

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...