我正在使用jQuery并尝试加载一个变量来代替命名的xml文件。 我的代码:在XMLHttpRequest中使用变量名称
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('#theForm').ajaxForm(function(responseXML2) {
var myxml = responseXML2;
alert(responseXML2);
displayResult();
});
});
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
alert("loading xmlhttprequest");
xhttp=new XMLHttpRequest();
}
else
{
alert("loading activeX");
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
alert("bottom load");
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
function displayResult()
{
alert("setting vars");
alert("displayResult called");
//xml=loadXMLDoc(responseXML2); //tried this and the line below, among others
xml=responseXML2;
alert("xmlDocLoaded");
xsl=loadXMLDoc("xslt-test.xsl");
alert("XSLloaded");
// code for IE
if (window.ActiveXObject)
{
alert("IE");
ex=xml.transformNode(xsl);
document.getElementById("ieiresponse").innerHTML=ex;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
alert("notIE");
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("ieiresponse").appendChild(resultDocument);
}
}
在上面的代码我想有:
//xml=loadXMLDoc(responseXML2); //tried this and the line below, among others
xml=responseXML2;
,而不是一个文件名为:
xsl=loadXMLDoc("example.xml");
当我通过代码运行,它的工作原理,如果我给这个文件起了名字,但是当我使用这个变量的时候(它出现在警报中,所以被拉出来),它会停止上面的代码(把变量放在xml文件中)
任何帮助将不胜感激!先谢谢你。
你有jQuery并做类似'if(window.XMLHttpRequest)'的事情吗?为什么?! – Tomalak 2010-05-17 19:01:56
我使用jQuery来检索表单发布的XML响应。如果有更好的方法(我是XML新手),我非常开放! – Paul 2010-05-17 19:09:21
我正在查看更多的代码,它看起来像responseXML2没有被拉入新的功能。我试图把现有的displayresult()代码底部在这里下: $( '#theForm')给ajaxForm(函数(responseXML2){ VAR myxml = responseXML2; 警报(responseXML2); 配售代码在这里 没有运气,现在它甚至没有调用警报! – Paul 2010-05-17 19:10:47