jQuery AJAX call returns "Not Found" error when attempting to upload image

Partha Mandayam 91 Reputation points
2023-08-08T13:34:37.4266667+00:00
// Function to handle file upload
alert("handlefileupload");
$.ajax({
    type: "POST",
    url: "ImageUploader.ascx/HandleFileUpload",
    data: '', //formData,
    //contentType: false,
    //processData: false,
    success: function (data) {
        // Handle the server response here
        alert("success");
        document.getElementById('<%= Label1.ClientID %>').innerText = "File uploaded successfully.";
    },
    error: function (xhr, status, error) {
        // Handle error if necessary
        alert("error");
        console.log(error);
        console.log(status);
        console.log(xhr);
    }
});

I have a function to handle a file upload but it is returning a "Not Found" error. The code should look for "HandleFileUpload" inside control "ImageUploader.ascx" code behind, but it's behaving strangely and creating a URL as "http://localhost:56722/ImageUploader.ascx/HandleFileUpload". Why is this happening?

Developer technologies | ASP.NET | Other
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.