C# Ajax调用成功失败了

C# Ajax调用成功失败了,c#,jquery,ajax,asp.net-mvc,C#,Jquery,Ajax,Asp.net Mvc,即使在服务器端方法上已达到并返回success=true,此ajax调用也不会在成功时创建警报 @model IEnumerable<Test.Models.Task> @Styles.Render("~/Content/Site.css") @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> @Html.ActionLink("Create New", "Create") <

即使在服务器端方法上已达到并返回success=true,此ajax调用也不会在成功时创建警报

@model IEnumerable<Test.Models.Task>
@Styles.Render("~/Content/Site.css")
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>

    <div id ="alerts">

           @Html.Action("_Tasks")
           <script type="text/javascript">
               $(document).ready(function poll() {

                    $.ajax({                       
                        type: 'GET',
                        cache: false,
                        url: '@Url.Action("TasksRefresh")',
                        dataType: "json", 
                        complete: function () { setTimeout(poll, 10000); },                      
                        success: function (data) {
                            alert("Testing")

                        } 
                    });
                })();
        </script>

       @* <script type="text/javascript">
            var alerts = '@ViewBag.Alerts';
           @foreach (var i in alerts)
           {

           }
        </script>*@

    </div>
<table>
    <tr>
        <th>Category</th> 
        <th>Severity</th>
       <th>Assigned to Role</th>
        <th>Assigned To</th>
        <th>Chart #</th>
        <th>Note</th>
        <th>Alert</th>
        <th>Status</th>
        <th>Creator By</th>
       <th>Create Date</th>
        <th>Due Date</th>



        <th></th>

    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.LookupTaskCategory.CategoryName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.LookupTaskSeverity.SeverityName)
        </td>    

        <td>
            @Html.DisplayFor(modelItem => item.AssignedToRoleName)
        </td>

        <td>
            @Html.DisplayFor(modelItem => item.AssignedToName)
        </td>

        <td>
            @Html.DisplayFor(modelItem => item.Patient.ChartNo)
        </td>

        <td>
            @Html.DisplayFor(modelItem => item.Note)
        </td>

        <td>
            @Html.DisplayFor(modelItem => item.AlertFlag)
        </td>

        <td>
            @Html.DisplayFor(modelItem => item.LookupTaskStatu.StatusName )
        </td>

        <td>
            @Html.DisplayFor(modelItem => item.CreatedByName)
        </td>

        <td>
            @Html.DisplayFor(modelItem => item.CreatedOnDate)
        </td>

        <td>
            @Html.DisplayFor(modelItem => item.DueDate)
        </td>

        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
            @Html.ActionLink("Details", "Details", new { id=item.Id }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.Id })
        </td>
    </tr>
}

</table>

服务器上出现异常-请尝试调试.NET代码,或使用浏览器工具查看您的响应,以查看异常

如果要在
GET
方法上返回JSON对象,则需要在
JSON
调用中包含
JsonRequestBehavior
参数,如:

return Json(new { success = true }, JsonRequestBehavior.AllowGet);
编辑


实际上,如果您在服务器上调试,您似乎看不到它-您必须在响应中看到它。显然,异常在
Json
方法之后被进一步抛出。

$(document.ready()
块之后的
()
不正确。无法从
.ready()
调用返回值,因为它不是函数。这将导致错误-在处理客户端代码时,应该始终打开错误控制台!如何让VisualStudio中的错误控制台看到ajax错误?顺便说一句,你的解决方案不正确。那不是一个解决方案。您不会使用VisualStudio来查看我所说的错误。这是客户端错误,所以您应该使用浏览器的调试工具。没问题。如果你感兴趣的话,它背后的安全目的是什么?有点古怪的漏洞,但它是有道理的。但是这已经吸引了我很多次了——我总是在我所有的AJAX调用中发布,所以我不会一直忘记这一点。
return Json(new { success = true }, JsonRequestBehavior.AllowGet);