我们如何将文本文件的内容从项目文件路径复制到 javascript 中的字符串变量。
我使用了下面的代码,但它给出了“拒绝访问”错误。
var sHTML = "";
var rawFile = new XMLHttpRequest();
rawFile.open("GET", "file://~/Templates/NewGridTemplate.txt", true);
sHTML = rawFile.responseText;
读取 C# 代码中的 html 模板,然后将其发送到您的 html 代码并分配给 innerHTML
using (StreamReader sr = new StreamReader(@"D:\Template.html")){
// Read the stream to a string, and write the string to the console.
obj.svar = sr.ReadToEnd().Replace(Environment.NewLine, " ");
//Console.WriteLine(line);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句