I have the following js code:
var ret;
$.ajax({
type: 'GET',
url: '/Pay/Build64/',
dataType: 'json',
complete: function(response) {
ret = response.Message;
},
async: false
});
alert(ret);
My action:
public JsonResult Build64()
{
return Json(new
{
Message = "Test"
});
}
The Build64 is called. But ret is undefined. Where is a error?
Whenever you return JsonResult you have to specify JsonRequestBehavior.AllowGet otherwise it will give error, for demo see this blog link controller code.