JavaScript函数无响应 [英] JavaScript function not responsive

查看:78
本文介绍了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!

这篇关于JavaScript函数无响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆