I am currently making an ajax call to my controller with the following code:
$.ajax({ type: "POST", url: "@Url.Action("uploadImage", "Item")", data: '{ "imageData" : "' + image + '" }', contentType: "application/json; charset=utf-8", dataType: "json", success: function (success) { alert('Success ' + success.responseText); }, error: function (response) { alert(response.responseText); } });
This is the controller:
[HttpPost] public ActionResult uploadImage(string imageData) { string imageName = Guid.NewGuid().ToString(); try { ProductManager pm = new ProductManager(); pm.AddNewProduct(imageName); }catch(Exception e) { writeToLog(e); } return Json(new { success = imageName }, JsonRequestBehavior.AllowGet); }
It goes to the controller and the AddNewProduct function succeeds. The problem is that I want it to return the image name created in the controller. This works, but with that, it also returns my full html page. I warn something about success and when an error occurs, but for some reason it always ends with an error with the following warning:

shows the value I need, but why does it also return my full HTML code?
source share