I am currently working on initiating an AJAX call to a controller ActionResult within the MVC framework. While I have experience with AJAX, I am relatively new to MVC. I have set up an AJAX call in a separate .js file that is triggered by a button click event in one of the views. The AJAX call is executed as expected but consistently returns a "resource not found" error message. See the code snippet below:
Button in View:
<input type="button" class="btn btn-success" value="Download Pictures" id="btnGetPics"/>
AJAX Call:
var ajaxURL = 'MMRController/TestAjax';
$('#btnGetPics').on('click',
function () {
$.ajax({
type: 'POST',
url: ajaxURL,
data: param = "this",
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: function () {
console.log('initiating ajax call');
},
success: function (data) {
alert(data);
},
error: function (ex) {
console.log('Error');
console.log(ex.responseText);
alert("Error occurred while downloading images. Please contact IT support.");
}
});
});
ActionResult within Controller:
[HttpPost]
public ActionResult TextAjax(string param)
{
return Json(param + " works", JsonRequestBehavior.AllowGet);
}
Displayed error message:
If you can provide any assistance, it would be highly appreciated.