只要单击按钮,我的Web服务器就会发送xmlhttprequest来编写JSON文件。但是,该文件在写入时只具有读取权限。此外,仅当Web服务器要求执行cgi脚本时才会发生这种情况。但是,如果我尝试从命令行自己执行此cgi脚本,则该文件将具有读写权限。有什么办法可以让web服务器让这个cgi脚本写一个具有完全权限的文件吗?
根据要求,这是我的代码中发送xmlhttprequest和fetches / json文件的部分。
<script>
function loadXMLdoc() {
var xmlhttp = new XMLHttpRequest();
var url = "/cgi-bin/run.cgi"
var id = document.getElementById("inputId").value;
var mutation = document.getElementById("inputMutation").value;
var position = document.getElementById("inputPosition").value;
var json;
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status==200) {
$.getJSON("data.json",function(result){
$.each(result, function(i, field){
output = "<h1>Output<h1>"
for (var f in field){
output+="<p>Identifier: " + field[f]["value"]+" Position: "+field[f]["position"]+" Mutation: "+field[f]["mutation"]+"</p>"
}
});
});
document.getElementById("test_container").innerHTML = output
}
}
xmlhttp.open("GET", url+"?id=" + id + "&mutation=" + mutation + "&position=" + position, true);
xmlhttp.send()
}
</script>
这是run.cgi中写入文件的部分。
write_file = open("%s/data.json" %(root_directory), 'w')
write_file.write('{"results": [\n')
for i,result in enumerate(results):
write_file.write('\t{"value": "%s", "mutation": "%s", "position": "%s"}' % (result["value"], result["mutation"], result["position"]))
if i != len(results) - 1:
write_file.write(",")
write_file.write("\n")
write_file.write("]}")
write_file.close()