我有一个简单的HTML,在标签上我有onmouseover="loadQueryResults();"
这是一个功能:
function loadQueryResults(e) {
e = e || window.event;
var data = [];
var target = e.srcElement || e.target;
while (target && target.nodeName !== "TR") {
target = target.parentNode;
}
if (target) {
var cells = target.getElementsByTagName("td");
for (var i = 0; i < cells.length; i++) {
data.push(cells[i].innerHTML);
}
}
//window.open("racun.php?name="+data) THIS WORKS
//window.alert("racun.php?name=" + data) THIS WORKS
//document.writeln(data);
final=data.toString();
//document.writeln(final); THIS ALSO WORKS
stranica="racun.php?name="+final;
$( "#DisplayDiv" ).load(stranica); //THIS DOESNT WORK---WHY???
$( "#DisplayDiv" ).load("racun.php"); //THIS however WORKS!
}
问题是,为什么当我在php页面中包含我要加载的参数时,没有任何反应?
答案 0 :(得分:1)
我认为cell [i] .innerHTML有空格或字符,不允许在网址中使用!
你应该使用这个函数来过滤'final'变量:
final = encodeURIComponent( data.toString() );
答案 1 :(得分:1)
尝试根据jQuery文档传递params:
$( "#DisplayDiv" ).load("racun.php", {name: data.toString() });
&#34; final&#34;看起来像保留字