Ajax调用中的解析器错误

时间:2017-06-07 07:07:44

标签: ajax

我试图通过Ajax调用从html页面调用控制器方法,脚本如下,

<script>
    $.ajax({
        url: '/Controllet/getAuth',
        type: "Post",
        data: {
            token: "skgdajshdgfyvbjgydsa",
            userId: "user1"
              },
            cache: false,
            dataType: "json",
            async: true,
            contentType: false,
            processData: false,
            success: function (response) {
                if (response != null && response.success) {
                    alert(response.responseText);        
                } else {
                    //do something else
                }
            },
            error: function (xhr, status, err) {
                alert('Response code:' + xhr.status);
                alert('[Error:' + err + '] ' + status);
            }
        });

我的控制器方法如下所示

private async Task<JsonResult> GetAuth(string token, string userId)
{
    try
    {
        //do something
        return Json(new { success = true, responseText = "!" },
        JsonRequestBehavior.AllowGet);
    }
    catch (Exception ex)
    {
        return Json(new { success = false, responseText = " "
        + ex.Message }, JsonRequestBehavior.AllowGet);
    }
}

每次运行时我都会得到[错误:SyntaxError:意外的令牌&lt;在位置2的JSON中] parsererror

0 个答案:

没有答案