I have been trying to get a jquery ajax function to return data from an orchard controller but so far I have not been successful. I have a break point set on the Controller but the code never reaches the controller.
Here is the JQuery function
<table id="tblResults" class="tablesorter">
<thead>
...
</thead>
<tbody>
@foreach (dynamic item in Result)
{
<tr>...</tr>
}
</tbody>
</table>
<input id="__requesttoken" type="hidden" value="@Html.AntiForgeryTokenValueOrchard()" />
@using (Script.Foot())
{
<script type="text/javascript">
//<![CDATA[
$(function () {
$("#tblResults").tablesorter();
setInterval(update, 20000);
});
function update() {
$.ajax({
type: 'POST',
url: '@Url.Action("GetResults", "ResultsController", new { area = "Orchard.App" })',
data: { token: $("#__requesttoken").val() },
success: function (response) {
alert(response);
},
error: function () {
alert('error');
}
});
}
//]]>
</script>
}
And For the ResultsController I just have this
[OutputCache(Duration = 0)]
public JsonResult GetResults()
{
var json = DateTime.Now.ToString();
return Json(json, JsonRequestBehavior.AllowGet);
}
NOTE: The Ajax call executes just fine however it never hits the break point set at “GetResults” and the http post url I see is “http://localhost:30320/OrchardLocal/”
Also, what I get for the response is the entire HTML Page.
Thanks in advance
Drop Controller after Results: “Results”, not “ResultsController”. Also, you’ll need to include the anti-forgery token in that post. Oh, and setInterval is evil.