没有位置重新加载的异步更新

时间:2014-08-31 06:06:25

标签: javascript jquery

我有一个加载XML数据的脚本,并且根据select语句,它会加载某些记录。 我发现在onchange上发出了location.reload(),实际上刷新了所有内容,并正确加载了数据。虽然,它在Chrome中并没有这样做。它只是将所选项目返回到其默认状态。

我已经阅读过异步更新,我想知道这是否可以在这里使用。

这是我的选择,在JS中,因为我发现加载XML项目作为选项的方式:

xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","line-perf.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<form name='lineForm'><div class='line-sel'>Line: ");
var x=xmlDoc.getElementsByTagName("SVC");
document.write("<select name = 'linesel' id='select1' onChange='line=this.value;location.reload();'>");
for (i=0;i<x.length;i++)
    {
    document.write("<option>");
    document.write(x[i].getElementsByTagName("LINE")[0].childNodes[0].nodeValue);
    document.write("</option>");
    }
document.write("</select></div></form>");

如果无法完成,那么如何在重新加载后避免Chrome默认选择语句?

感谢您的帮助。

更新

这是使用select值加载XML的脚本的其余部分:

line = document.lineForm.linesel.value;
    document.write("<img class='linelogo' src='images/lines/"+line.toLowerCase()+".png'>");
    xmlhttp=new XMLHttpRequest();
    xmlhttp.open("GET","Services.xml",false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML;
    document.write("<table align='left' border='0' cellpadding='0' cellspacing='0' width='340' height='300' class='svc-mat'><tr>");
    var x=xmlDoc.getElementsByTagName("SVC");
    var col=0;
    for (i=0;i<x.length;i++)
        {
        if (line != "ALL") {
            if (x[i].getElementsByTagName("LINES")[0].childNodes[0].nodeValue.search(line) != -1) 
                {
                document.write("<td><ul><li><a href='svc-det.html?name=");
                document.write(x[i].getElementsByTagName("CODE")[0].childNodes[0].nodeValue.replace(/\s+/g, '_'));
                document.write("'>");
                document.write(x[i].getElementsByTagName("CODE")[0].childNodes[0].nodeValue);
                    if (col==4 || col==9 || col==14 || col==19 || col==24 || col==29 || col==34 || col==39 || col==44 || col==49 || col==54 || col==59) {
                    document.write("</a></li></td></tr><tr>");}
                    else {
                    document.write("</a></li></td>");
                    }
                col++;
                }
            } else {
                    document.write("<td><ul><li><a href='svc-det.html?name=");
                    document.write(x[i].getElementsByTagName("CODE")[0].childNodes[0].nodeValue.replace(/\s+/g, '_'));
                    document.write("'>");
                    document.write(x[i].getElementsByTagName("CODE")[0].childNodes[0].nodeValue);
                        if (i==4 || i==9 || i==14 || i==19 || i==24 || i==29 || i==34 || i==39 || i==44 || i==49 || i==54 || i==59) {
                        document.write("</a></li></td></tr><tr>");}
                        else {
                        document.write("</a></li></td>");
            }
        }
    }
    document.write("</ul></tr></tbody></table>");

0 个答案:

没有答案
相关问题