简体   繁体   中英

How do i load information from a textfile in Asp.net?

I want to use the ()Load method. I have done it without a problem on PHP but now I want to do the same on 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. I put the "footershop.txt" in the App_Data folder. 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. 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

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM