简单地将变量的值从PHP文件传递给JavaScript函数

时间:2014-07-29 08:05:26

标签: javascript php jquery

我想从PHP文件传递变量的值,以将其用作JavaScript函数的参数。 E.g:

PHP:

$passed = "passed";
$failed = "failed";

$name = $_POST['name'];

if($name == "lekz"){
     echo $passed; // this variable will pass to js file
}
else{
    echo $failed; // this variable will pass to js file
}

JS:

function trace(){

    var con = "passed"

    if($passed == con){
        alert("passed");
    }
    else{
        alert("failed");
    }
}

我能以什么方式将变量从PHP传递到JS函数?

0 个答案:

没有答案