我想从一个JavaScript执行一个PHP脚本(基本上是更新一个SQL数据库)。
我读了一些东西,但并不成功。
我尝试了,但它看起来总是执行
arrr.length
的值。
脚本
$(document).ready(function(){
$("#submitcode").on("click", function(){
if (document.getElementById('VT').value ==0 || document.getElementById('VE').value ==0 || document.getElementById('VS').value ==0){
$("#output").text("Cannot Start experiment with at least one empty volume !");
}
else {
ocpu.seturl("https://public.opencpu.org/ocpu/library/base/R")
//arguments
var mysnippet = new ocpu.Snippet("V_T <- "+document.getElementById('VT').value+" \r"+"V_E <- "+document.getElementById('VE').value+" \r"+"V_S <- "+document.getElementById('VS').value+" \r"+$('#input2').val());
//perform the request
var req = ocpu.call("identity", {
"x" : mysnippet
}, function(session){
session.getObject(function(dataR) {
arrR = JSON.parse(dataR);
if (arrR.length > 0){
$("#output").text("Experiment just started");
// this is where I would like to launch and execute the PHP file when submitcode is clicked and arrR.length > 0
// this is where I would like to launch and execute the PHP file when submitcode is clicked and arrR.length > 0
// this is where I would like to launch and execute the PHP file when submitcode is clicked and arrR.length > 0
}
});
});
}
})
});
要执行的PHP
<?php
include_once '../admin/admin-class.php';
$admin = new itg_admin();
$admin->_authenticate();
include '../db/db_simple.php';
$idTP = $admin->get_id();
mysql_query("UPDATE `userTP` SET `inprogress` = '1', `launchedat` = now() WHERE `userTP`.`id` =".$idTP);
mysql_close($connection);
?>
您不能在浏览器客户端运行PHP代码。 您应该向服务器/本地主机中的PHP文件发送请求,并随请求传递数据。 对于发送请求,可以使用JQuery Ajax。 很简单。 这里有一个简单的教程