使用php代码中的参数调用javascript函数

时间:2014-11-13 10:48:09

标签: javascript php ajax

我想从php调用javascript函数并执行ajax调用。我的php代码是:

echo '<script>change2('.$stand.'); </script>';

我的js代码是:

function change2(c){
alert(c);
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
    }

    xmlhttp.open("GET","change2.php?c="+c,true);
    xmlhttp.send();

    }

警报返回未解决..

1 个答案:

答案 0 :(得分:0)

你可以这样做:<input type="hidden" value="<?php $stand ?>" id="someID"> 在你的Js

<script>change2(document.getElementByID('someID'); </script>

我认为它有效。