Mohan Prasath Mohan Prasath - 5 months ago 15x
Javascript Question

My AJAX responses are getting downloaded rather than getting loaded in success data

I am quiet new to JQuery. I am sending an AJAX request (File Upload) to WEB API (ASP.NET MVC) but my responses are getting downloaded as JSON file rather than the loaded to success data.

Please find the code in the HTML below

$('#myForm1')[0].submit(function (event) {
//grab all form data
var formData = new FormData($(this)[0]);
url: 'http://localhost:102/webapi/api/values/All',
type: 'POST',
data: formData,
datatype : "json",
//async: false,
//cache: false,
contentType: true,
processData: false,
complete: function () {
success: function (returndata) {
// $("#productFormOutput").html(returndata);
error: function () {
alert("error in ajax form submission");

return false;

enter image description here

BTW no alert messages in success, error and complete is called after getting the response. But Fiddler shows the response is successful (HTTP 200). Is anything am I doing wrong while calling the request?


Removing [0] and changing the input to 'submit' in form solved my problem

$('#myForm1')[0].submit(function (event) 

As Roland said, submit with button in input tag is not handling the event handler