Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/479.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 想要使用php查看json文件数据吗_Javascript_Php_Json - Fatal编程技术网

Javascript 想要使用php查看json文件数据吗

Javascript 想要使用php查看json文件数据吗,javascript,php,json,Javascript,Php,Json,我用json文件数据创建了一个crud系统。我使用javascript将数据查看到html文件中。但我认为这会引起一些安全问题。我想使用php而不是JavaScript创建数据视图 这是我的JavaScript视图文件 var output = document.getElementById('output'); var ajaxhttp = new XMLHttpRequest(); var url = "form.json"; var xhttp = new XMLHttpReques

我用json文件数据创建了一个crud系统。我使用javascript将数据查看到html文件中。但我认为这会引起一些安全问题。我想使用php而不是JavaScript创建数据视图

这是我的JavaScript视图文件

var output = document.getElementById('output');

var ajaxhttp = new XMLHttpRequest();

var url = "form.json";

var xhttp = new XMLHttpRequest();
var details = '';
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {

        var response = JSON.parse(xhttp.responseText);

                var output = '';

                output += "<table class='table table-bordered'>";
                output += "<tr><th scope='col'>id</th><th>First Name</th><th>Last Name</th><th>Age</th><th>Action</th></tr>";              

                for(x in response){

                    if(response[x].is_active == "1"){


                    output += "<tr><td>" + response[x].id + "</td><td>" + response[x].firstname + "</td><td>"+response[x].lastname+"</td><td>"+response[x].age+"</td><td><a href='edit.php?id="+response[x].id+"&firstname="+response[x].firstname+"&lastname="+response[x].lastname+"&age="+response[x].age+"' class='btn btn-primary btn-sm active' role='button' aria-pressed='true'>Edit</a><a href='update.php?id="+response[x].id+"&firstname="+response[x].firstname+"&lastname="+response[x].lastname+"&age="+response[x].age+"' class='btn btn-danger btn-sm' role='button' data-toggle='modal' data-target='#exampleModal' name='btnDelete' style='margin-left: 10px;'>Delete</a></td></tr>";

                    }

                }

                output += "</table> ";
               document.getElementById("output").innerHTML = output;

    }
};
xhttp.open("GET", url, true);
xhttp.send();
var output=document.getElementById('output');
var ajaxhttp=new-XMLHttpRequest();
var url=“form.json”;
var xhttp=newXMLHttpRequest();
var详细信息=“”;
xhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
var response=JSON.parse(xhttp.responseText);
var输出=“”;
输出+=“”;
输出+=“idFirst NameLast NameAgeAction”;
用于(x响应){
如果(响应[x]。是否处于活动状态=“1”){
输出+=“”+响应[x]。id+“”+响应[x]。名字+“”+响应[x]。名字+“”+响应[x]。年龄+“”;
}
}
输出+=“”;
document.getElementById(“输出”).innerHTML=output;
}
};
xhttp.open(“GET”,url,true);
xhttp.send();

我想用php做同样的事情。有人能帮我吗?

您可以使用PHP的
curl
函数来执行来自PHP的等效AJAX请求

您可以使用
json\u decode()
将json转换为PHP对象和数组

使用
htmlspecialchars()
转义输出


如果要修复JS代码,请在输出时转义数据库中的所有内容。请参阅或使用jQuery的
.text()
函数填充该表。

是否要在php中重写该函数?请澄清。是的,我想用php重写