Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOM object constructor cannot be called as a function

I have this function on javaScript, and works on Firefox, but on google chrome not

function sendInfo(userId, Code) {
            // text with all info to send to controller
            var values = {
                "token": Code,
                "code": userId
            }

            // POST THE CHANGE HERE TO THE DATABASE
            var url = "WSHolFacebook.asmx/saveToken";
            $.post(url, values, function (data) {
                if (window.ActiveXObject) { return data.xml; }
                var xmlString = XMLSerializer().serializeToString(data);
                var xml = xmlString,
                xmlDoc = $.parseXML(xml),
                $xml = $(xmlDoc),
                $title = $xml.find("string");
                var texto = $title.text();
                if ($title.text() == "Success") {
                    window.location = '<%=ConfigurationManager.AppSettings["successUrl"].ToString() %>'
                }
                else {
                    window.location = '<%=ConfigurationManager.AppSettings["errorUrl"].ToString() %>'
                }
            })
        }

the error in chrome it is:

Uncaught TypeError: DOM object constructor cannot be called as a function.

like image 287
r-magalhaes Avatar asked Mar 22 '13 15:03

r-magalhaes


1 Answers

Change

var xmlString = XMLSerializer().serializeToString(data);

to

var xmlString = new XMLSerializer().serializeToString(data);

The reason it throws the error is because you are trying to invoke XMLSerializer as a function instead of instantiating it.

like image 155
Brad M Avatar answered Nov 20 '22 17:11

Brad M