简体   繁体   English

为什么要在我的自定义错误消息中添加“无效的JSON”

[英]Why getting “Invalid JSON” added to my custom error message

Invalid JSON: 无效的JSON:

Error 1 : Non-MDX format found.     

Why I am getting the Invalid JSON with my custom error message. 为什么我收到带有自定义错误消息的无效JSON。

My code is given bellow: 我的代码如下所示:

$('#btnCreateView').click(function (e) {
    e.preventDefault();
    $.ajax({

        type: "POST",
        url: '@Url.Action("Create", "Mdx")',
        data: $('form').serialize(),
        dataType: "json",

        success: function (result) {
            alert("View Created Successfuly");
            window.location = result.link;

        },
        error: function (jqXhr, textStatus, errorThrown) {
            $('#ErrorMessageField').html(errorThrown);
        }

    });
})

In your controller action you seem to be returning a partial view: 在控制器操作中,您似乎正在返回部分视图:

return PartialView("Fail");

but in your AJAX request you inidicated 但是您在AJAX请求中建议

dataType: "json",

Obviously this is inconsistent. 显然这是不一致的。 When jQuery attempts to parse the string returned from your controller action back into javascript object it fails because you are not sending JSON, you are sending partial HTML. 当jQuery尝试将控制器操作返回的字符串解析回javascript对象时,由于未发送JSON而失败,而是发送了部分HTML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的行未添加到表中? - Why isn't my row getting added to my table? 现在将所有aspnetuser表添加到我的数据库中,出现此错误 - Added all the aspnetuser tables to my database now getting this error 从MVC AJAX调用中获取“无效的JSON原语”错误 - Getting “Invalid JSON primitive” error from MVC AJAX call 如何从Json文件为模型属性添加自定义错误消息? - How to add custom error message for model property from Json file? 无效的JSON解析器错误 - Invalid JSON Parser Error 当我在ajax调用中返回太多行作为json时,为什么会出现Http错误500? - Why am I getting Http error 500 when I return too many rows as json in my ajax call? 未在日期列表的数据注释上的无效值错误消息中获取字段名称 - Not getting field name in invalid value error message on Data annotation for list of dates 为什么这个额外的“?_=1579068576376”被添加到我的 API 请求的 URL '/api/customers' - why this extra "?_=1579068576376" is getting added to the URL '/api/customers' for my API request 为什么返回原始 JSON 对象而不是我的部分视图? - Why is the raw JSON object getting returned instead of my partial view? 自定义错误消息MVC - Custom Error Message MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM