I attempted to invoke a method in an asp.net controller using a json string/object from javascript.
The asp.net controller code is as follows:
public class HomeController : Controller
{
public ActionResult doWork(string data) {
// dowork..
return new EmptyResult();
}
}
Within the javascript, I have the following snippet:
var XHR=new XMLHttpRequest();
XHR.open("GET", 'http://localhost:58476/home/dowork', true);
XHR.setRequestHeader("Accept","application/json");
XHR.onreadystatechange = function () {
if (XHR.readyState == 4 && XHR.status == 200) {
alert('ok');
}else{
alert('not ok');
}
};
XHR.send(JSON.stringify(queryResult));
When the javascript runs, it calls the dowork method in asp.net, but the data parameter is null. The onreadystatechange event triggers the 'not ok' alert.
In my console log, I discovered the error message:
XMLHttpRequest cannot load http://localhost:58476/home/dowork. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access.
Does anyone know how to resolve this issue?