locked
jq ajax in web form fail to read text file RRS feed

  • Question

  • Hi   I copied example of ajax and tried to run it. I am using .net 4.6.1  web form. I am getting error: Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

    is this CORS issue? Please help

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Ajax._Default" %>
    
    <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    
        <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
    
    <button>Get External Content</button>
        <script>
            $(document).ready(
                function () {
                    $('button').click(
    
                    function () {
                        $.ajax({
                            url: "./test.txt",
                            
                            success: function (data) {
    
                                $('#div1').innerHtml = data;
                            }
                        });
                    })
                    }
    );
    
        </script>
    
    </asp:Content>

    I am getting run time error:Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

    • Moved by CoolDadTx Wednesday, March 6, 2019 6:36 PM ASP.NET related
    Wednesday, March 6, 2019 3:30 PM

All replies

  • You have a misunderstanding about Ajax and how to use it. A test.tx is not a URL to a Web method that is doing a  GET. POST, PUT or DELETE. Maybe, you need to get a book or something on how to use AJAX.

    AJAX can be discussed at the ASP.NET forums.

    https://forums.asp.net/

    Wednesday, March 6, 2019 4:34 PM
  • I tested the code with plain html  file. It worked...
    Wednesday, March 6, 2019 4:54 PM
  • Please post questions related to web development in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, March 6, 2019 6:36 PM