I have a project in Asp.Net MVC with the following method:
public ActionResult ObterCursos()
{
List<curso> cursos = new List<curso>();
curso curso_ = new curso();
curso_.Nome = "Análise";
curso_.Periodo = 3;
curso_.qtdSemestre = 5;
curso_.Codigo = "ADS";
cursos.Add(curso_);
curso_ = new curso();
curso_.Nome = "Ciencia da Computação";
curso_.Periodo = 3;
curso_.qtdSemestre = 8;
curso_.Codigo = "CDC";
cursos.Add(curso_);
return Json(cursos, JsonRequestBehavior.AllowGet);
}
As you can see, it returns a Json
as a result. I'm running such a project on my local machine.
Home
In another project, I'm trying to make an Ajax request to the method created in the project described above.
$.ajax({
url : "http://localhost:10642/Mobile/ObterCursos",
type : "GET",
dataType : "json",
success : function(dados) {
resultado = dados;
alert("json sucess")
},
error : function(xhr, ajaxOptions, error) {
alert("erro json: " + xhr.responseText)
}
});
When it is run,% w of error is shown and the following error is displayed in the console:
XMLHttpRequest can not load link . In 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Performing my searches, I discovered that I should change the alert
from dataType
to Ajax
. And so I did, but the% error with error is still shown, however the error that was displayed in jsonp
no longer appears.
Home
Can anyone help me?