如何从responseText获取错误消息的一部分

时间:2020-01-27 13:35:57

标签: javascript jquery json error-handling

我有一个错误功能,我试图仅显示部分消息 如下:

function onError(result) {
                           // alert(result.responseText);
                            var message = JSON.parse(result.responseText).more_info;
                            $('<div>' + message + '</div>').dialog({
                                modal: true,
                                resizable: false,
                                title: "Test",
                                buttons: { "Okay": function () { $(this).dialog("close"); } }
                            });
                        }

但是以上消息以未定义形式返回。 这就是我的结果返回的方式

{\"more_info\":\"method should have required property\",\"category\":\"api_request_error\",\"description\":\"One or more request parameters are invalid.\"}"

我只想在我的消息中显示“ more_info”字符串。因此我的消息应仅显示“方法应具有必需的属性”

我该如何实现?

0 个答案:

没有答案
相关问题