感谢我在这里收到的帮助,我有一段javascript,可以切换div的可见性,并将内容从php文件加载到切换的div中:
function compare_toggle_visibility(id, line, collection)
{
var e = document.getElementById(id);
e.style.display = ((e.style.display!='none') ? 'none' : 'block');
$(e).load('http:/www.minorworksoflydgate.net/XML/XQuery/test_command_line.php'+ '?collection=' + collection + '&zone=' + id + '&line=' + line, function(responseTxt, statusTxt, xhr){
if(statusTxt == "success")
alert("External content loaded successfully!");
if(statusTxt == "error")
alert("Error: " + xhr.status + ": " + xhr.statusText);
});
}
这适用于我用于测试的小型php文件,但我遇到的问题是我的实际生产文件需要一些时间来加载。因此,在将代码加载到div之前,div会切换并存在。我收到了警告消息,作为测试表明外部内容已加载,但我在div中看不到任何内容。
为了解决这个问题,我尝试在加载功能之后放置切换,但这没有任何区别。我也尝试将php调用的结果加载到变量中,然后在成功加载时将该变量的结果调用到div中,但这也不起作用。
function compare_toggle_visibility(id, line, collection)
{
var e = document.getElementById(id);
e.style.display = ((e.style.display!='none') ? 'none' : 'block');
var l = load('http:/www.minorworksoflydgate.net/XML/XQuery/test_command_line.php'+ '?collection=' + collection + '&zone=' + id + '&line=' + line, function(responseTxt, statusTxt, xhr){
if(statusTxt == "success")
$(e).html(l);
if(statusTxt == "error")
alert("Error: " + xhr.status + ": " + xhr.statusText);
});
}
我不确定我哪里出错了 - 我对php和XML非常熟悉,但javascript更少,尤其是Ajax和Jquery。
答案 0 :(得分:1)
试试这个
function compare_toggle_visibility(id, line, collection){ var e = document.getElementById(id);
e.style.display = ((e.style.display!='none') ? 'none' : 'block');
$.get('http:/www.minorworksoflydgate.net/XML/XQuery/test_command_line.php'+ '?collection=' + collection + '&zone=' + id + '&line=' + line, function(responseTxt){
$(e).html(responseTxt);
});
}