【发布时间】:2014-09-05 02:22:37
【问题描述】:
我有以下代码:
var frm = $('#login');
frm.submit(function (ev) {
var postData = $(this).serializeArray();
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
datatype: "xml",
data: postData,
success: function (data, textStatus, jqXHR) {
var saml = $("saml2\\:Assertion", (new XMLSerializer()).serializeToString(data));
var $assertion = $('<div/>').text(saml[0].outerHTML);
$('<pre/>').appendTo('#body').text(vkbeautify.xml($assertion.text()));
},
error: function (jqXHR, textStatus, errorThrown) {
alert('login failed - '.concat(jqXHR.responseText));
}
});
我正在调用的服务正在返回一个 XML 文档,其中元素名称采用 CamelCase 格式。文档开始:
<ns3:RequestSecurityTokenResponse xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ns10="http://www.w3.org/2000/09/xmldsig#" xmlns:ns2="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://docs.oasis-open.org/ws-sx/ws-trust/200512/" xmlns:ns4="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns5="http://docs.oasis-open.org/ws-sx/ws-trust/200802" xmlns:ns6="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:ns7="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:ns8="http://schemas.xmlsoap.org/ws/2005/02/sc" xmlns:ns9="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
<ns3:RequestedSecurityToken>
我遇到的问题是,当我在调试器中检查返回的数据对象时(在执行以 'var saml' 开头的行之前有一个断点,我可以看到元素名称都是小写的,例如顶部-level 元素现在是 ns3:requestsecuritytokenresponse。
我可以看到线路上的消息是大写的。
任何想法如何防止 Ajax 强制元素名称为小写?
谢谢。
【问题讨论】:
标签: javascript jquery ajax xml