douxiong4892 2008-12-16 16:31
浏览 39
已采纳

javascript中的ajax php变量

I have the below code, which was previously working fine:

var xmlHttp
var layername
var url
function update(layer, url) {
    var xmlHttp=GetXmlHttpObject(); //you have this defined elsewhere

    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";
        }

       //etc
    }

    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}


function updateByPk(layer, pk) {
   url = "get_auction.php?cmd=GetAuctionData&pk="+pk+"&sid="+Math.random();
   update(layer, url);
}


function updateByQuery(layer, query) {
   url = "get_records.php?cmd=GetRecordSet&query="+query+"&sid="+Math.random();
   update(layer, url);
}

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");
var phpstring = <?php $out = htmlspecialchars(json_encode($row2['ARTICLE_DESC']), ENT_QUOTES); echo("'$out'"); ?>; 
child1.document.write(phpstring); 
//child1.document.write("<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']), ENT_QUOTES); ?>");
child1.document.close(); 
}

The part that is commeneted out was working fine in a previus version, in that javascript was replacing row2['ARTICLE_DESC'], a php variable with the contents of the variable. This javascript file is included from a script tag in a php file, and always worked fine. I have changed something recently however, I am not sure what the specific thing was, butnow I get these errors, from firebug:

function makewindows(){
    child1 = window.open ("about:blank");
    child1.document.write("<br />
    <b>Notice</b>: Undefined variable: row2 in <b>C:\Programme\EasyPHP 2.0b1\wwwecords4\fetchlayers.js</b> on line <b>57</b><br />
    null");
    child1.document.close();
    }

unterminated string literal on line 57 and the updateByQuery is not defined.

I have no idea why I get either of those errors, and why updateByPk does not throw an error. I am even more confused as to what article_Desc is being expanded to and how. This happens on the index.php, which has a link to call updateByQuery, which would load a section via ajax which would have a link to updateByPk, which would display the final section, which would have a link to makewindows(), where article_Desc would relate to the relevant $pk

This was all working fine, and I can not find out why it no longer is.

would it help if I were to paste the php files somewhere?

edit.

i do not understand why this is happening, but have tried to modified the function so it takes a paramter.

function makewindows(html){
child1 = window.open ("about:blank");
child1.document.write(html);
child1.document.close(); 
}

in conjunction with thse two snippets of php

$html = json_encode(htmlspecialchars($row2['ARTICLE_DESC']));

and

<a href='#' onclick='makewindows(/"".$html."/"); return false;'>Click for full description </a></p>
  • 写回答

1条回答 默认 最新

  • duandu9260 2008-12-20 03:52
    关注

    Everything indicates the problem is in your PHP file. The notice you are getting is from PHP and not from JavaScript as you may be assuming.

    <b>Notice</b>: Undefined variable: row2 in <b>C:\Programme\EasyPHP 2.0b1\wwwecords4\fetchlayers.js</b> on line <b>57</b><br />
        null");
    

    So the problem is in here:

    <?php $out = htmlspecialchars(json_encode($row2['ARTICLE_DESC']), ENT_QUOTES); echo("'$out'"); ?>; 
    

    The $row2 array is not defined, so $row2['ARTICLE_DESC'] doesn't exist. You should verify from where it should come from because I couldn't find it in the code you provided.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题