Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获类型错误:对象#<;对象>;没有方法';匹配';_Javascript_Jquery_Html_Dom - Fatal编程技术网

Javascript 未捕获类型错误:对象#<;对象>;没有方法';匹配';

Javascript 未捕获类型错误:对象#<;对象>;没有方法';匹配';,javascript,jquery,html,dom,Javascript,Jquery,Html,Dom,响应是一个html页面,title元素中有“Error”,并伴有无序的错误列表 下面检查页面标题是否为“错误”,如果是,则抓取无序列表中的第一条错误消息,并将其传递到displayAjaxMessage函数中 它返回一个错误:Uncaught TypeError:Object#在下一行没有方法“匹配”: if (html.match(/<title>Error<\/title>/)) $("#profile-edit-form").validate({ submi

响应是一个html页面,title元素中有“Error”,并伴有无序的错误列表

下面检查页面标题是否为“错误”,如果是,则抓取无序列表中的第一条错误消息,并将其传递到displayAjaxMessage函数中

它返回一个错误:Uncaught TypeError:Object#在下一行没有方法“匹配”:

if (html.match(/<title>Error<\/title>/))
$("#profile-edit-form").validate({
    submitHandler: function () {
        $.ajax({
            url: $("#profile-edit-form").attr("action"),
            data: $("#profile-edit-form").serialize(),
            dataType: "html",
            type: 'POST',

            error: function (jqXHR, textStatus, errorThrown) {
                displayAjaxMessage("Sorry, there was an error logging in, please try again.");
            },
            success: function (html, textStatus, jqXHR) {
                if (html.match(/<title>Error<\/title>/)) {
                    var error = $(html).find('ul li:first').text();
                    if (error == "The password you submitted was not correct") {
                        var error_msg = "<p>The password is incorrect</p>";
                        displayAjaxMessage("The password you submitted was not correct", "#profile-edit-form-response");
                        $('#error-modal').modal('show');
                        $('.error-modal-message').show().html(error_msg);
                    } else if (error == "You must submit your username and password") {
                        displayAjaxMessage("You must submit your username and password.");
                    }
                } else {
                    $('#profile-updated-modal').modal('show');
                }
            }
        });
    }
});

默认情况下,HTML似乎正在转换为某些对象

为什么不像对待列表一样对待标题标签呢

        success: function (html, textStatus, jqXHR) {
            var nodes = $(html);
            if (html.find("title").text()==="Error") {
                var error = nodes.find('ul li:first').text();

不知何故,jQuery似乎在解析对对象的响应,而不是将响应作为字符串发送给成功处理程序。因此,请尝试在ajax请求中设置
数据类型:“html”
选项。

如果
html
的值不是字符串,那么
match
方法将不会出现,它看起来像xml数据。。。你能确认一下这本书的内容类型吗response@ArunPJohny它返回htmlThen pass
数据类型:“html”
到ajax请求,并查看发生了什么事情到目前为止一切看起来都很好。。。console.log()的结果是什么。。。您是否尝试传递
数据类型:“html”
        success: function (html, textStatus, jqXHR) {
            var nodes = $(html);
            if (html.find("title").text()==="Error") {
                var error = nodes.find('ul li:first').text();