JavaScript函数无响应
我有以下代码,这是我的小型AJAX应用程序的核心部分.我没有收到任何错误,只是什么也没有发生.我猜想有一种更有效的方式来做我想做的事.
I have the following code, which is the core part of my small AJAX application. I am not getting any errors, it is just that nothing happens. I am guessing there is a more efficient way to do what I am trying to do.
这是代码:
var xmlHttp
var layername
function update(layer, part, pk, query)
{
if (part=="1")
{
$url "get_auction.php?cmd=GetAuctionData&pk="+pk+"&sid="+Math.random()
}
else if (part=="2")
{
var url "get_records.php?cmd=GetRecordSet&query="+query+"&sid="+Math.random()
}
xmlHttp=GetXmlHttpObject()
if(xmlHttp==null)
{
alert("Your browser is not supported?")
}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
document.getElementById(layer).innerHTML=xmlHttp.responseText
} else if (xmlHttp.readyState==1 || xmlHttp.readyState=="loading") {
document.getElementById(layer).innerHTML="loading"
}
};
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
xmlHttp=new XMLHttpRequest();
}catch (e)
{
try
{
xmlHttp =new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
return xmlHttp;
}
function makewindows(){
child1 = window.open ("about:blank");
child1.document.write(json_encode(<?php echo $row2["ARTICLE_DESC"]; ?>));
child1.document.close();
}
以及我如何从php调用函数的示例
and an example of how I am calling the function from php
onclick="update(\'Layer3\',\'2\','.$pk.'\',\'0\',)">'
pk或查询永远不会同时传递,只有其中之一会传递.
pk or query will never be passed at the same time, only one of them will ever be passed.
edit:我还想知道makewindows函数采用参数还是保持原样更有意义.每种方法都有优点和缺点吗?
edit: I am also wondering if it would make more sense for the makewindows function to take a parameter, or stay as it is. Are there advantages and disadvantages for each approach?
看起来您可能有一些javascript错误:
Looks like you may have some javascript errors:
if (part=="1")
{
$url "get_auction.php?cmd=GetAuctionData&pk="+pk+"&sid="+Math.random()
}
else if (part=="2")
{
var url "get_records.php?cmd=GetRecordSet&query="+query+"&sid="+Math.random()
}
使用Firefox并打开javascript控制台以获取javascript错误,然后尝试修复其抱怨的行.
Use Firefox and Open the javascript console to get the javascript errors, then try to fix the lines it complains about.
遇到错误,Javascript将立即停止运行.
Javascript will stop running as soon as it encounters an error.
如果还没有的话,请检出 firebug .很棒的工具!
Also, checkout firebug if you haven't already. Great tool!