我在javaScript上有这个功能,适用于Firefox,但谷歌浏览器不适用
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() %>'
}
})
}
Chrome中的错误是:
未捕获TypeError:无法将DOM对象构造函数调用为 功能的
答案 0 :(得分:5)
更改
var xmlString = XMLSerializer().serializeToString(data);
到
var xmlString = new XMLSerializer().serializeToString(data);
它抛出错误的原因是因为您尝试将XMLSerializer作为函数调用而不是实例化它。