[英]How do i load information from a textfile in Asp.net?
I want to use the ()Load method. 我想使用()Load方法。 I have done it without a problem on PHP but now I want to do the same on ASP.net.
我在PHP上没有遇到问题,但现在我想在ASP.net上做同样的事情。
<script>
$(document).ready(function () {
$("#btn").click(function () {
$("#test").load("footershop.txt")
});
});
</script>
<section class="shop">
<footer>
<img src="@Url.Content("~/Images/klader.jpg")" alt="klader">
<div id="test" >
<p class="shoptext">text</p>
</div><br />
<button id="btn">Mejla oss</button>
</footer>
</section>
Here is my code in ASP.net. 这是我在ASP.net中的代码。 I put the "footershop.txt" in the App_Data folder.
我把“footershop.txt”放在App_Data文件夹中。 It does not show up.
它没有显示出来。 Where should I put the textfile in ASP?
我应该把文本文件放在哪里?
you can use $.ajax instead of load
to show the textfile content in the div. 您可以使用$ .ajax而不是
load
来显示div中的文本文件内容。 The txt file should be in the same directory path for the below code to work else you have to specify the actual path at the url
property txt文件应位于相同的目录路径中以使下面的代码工作,否则你必须在
url
属性中指定实际路径
<script>
$(document).ready(function () {
$("#btn").click(function () {
$.ajax({
url : "footershop.txt",
dataType: "text",
success : function (data) {
$("#test").html(data);
}
});
});
});
</script>
you should be testing it from a server not from local system as there might access issues in local to read the txt file. 你应该从服务器而不是从本地系统测试它,因为在本地可能会访问读取txt文件的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.