我有那个
的JavaScript
flagQuery = session.reponseText;
alert(flagQuery);
flagQuery = JSON.parse(flagQuery);
contentElt.innerHTML = "valeur FLAG" + flagQuery;
我的javascript必须收到从php发送的标志。
上面的代码是收到时的标志处理。
在我的php中,我将变量flag声明为true。 如果可能的话,我想用Ajax来对待它。 我不知道在PHP中添加什么来获取JavaScript中的标志?
我不希望不得不用jQuery书店重载我的代码,我会将它用于半分代码。
答案 0 :(得分:2)
我假设想通过ajax请求访问php值。你可以在下面做那个谎言;
PHP: flag.php
<?php
$flag = "Your flag value";
echo $flag;
<强> JS:强>
$.ajax({
url: "flag.php",
type: "get",
success: function(data){
alert("Flag value is: " + data);
},
error:function(){
alert("Error occured!");
}
});
纯JS:
<script>
function getFlagValue() {
var xmlHttp;
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState==4 && xmlHttp.status==200) {
alert(xmlHttp.responseText);
}
}
xmlHttp.open("GET","flag.php",true);
xmlHttp.send();
}
</script>
答案 1 :(得分:0)
<强>你好。试试这个,看看你是否需要。
//PHP File
<?php
echo json_encode(array("one","two"));
?>
//Js File
$.get("page.php", function(data){
alert(data)
})