The following setup triggers the "success" event, however the response is simply the content of the aspx page.
HTML
<input id="fileInput" type="file" />
<button type="button" onclick="UploadFile();">Upload File</button>
Javascript
function UploadFile() {
var fileData = new FormData();
fileData.append('file', $('#fileInput')[0].files[0]);
$.ajax({
type: 'POST',
url: 'Upload.aspx/IngestFile',
contentType: false,
processData: false,
data: fileData,
success: function (response) {
console.log(response);
},
error: function (response) {
console.log(response);
}
});
}
C#
[System.Web.Services.WebMethod]
public static string IngestFile()
{
return "Hello World";
}
As far as I can tell, the ajax call is never reaching the WebMethod. As removing the data
and processData
ajax properties and using contentType: 'application/json'
returns the json object {d: "Hello World"}
as I was hoping for from the original ajax, and hits the breakpoint in the C# code.
Using jQuery 1.8.3.
Tried in Edge 87.0.664.66 and IE11
The only message in the console is the html of the page as loaded
<!DOCTYPE html>
<html>
...
</html>