我有以下javascript函数
function ajax_runs3(value){
var ajaxRequest; // The variable that makes Ajax possible!
try{
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.myForm.time.value = ajaxRequest.responseText;
}
}
var runs3= value;
ajaxRequest.open("POST","runs3.php"+ runs3, true);
ajaxRequest.send(null);
}
还有PHP文件
<?php
$servername = "localhost";
$username = "USER";
$password = "PASS";
$dbname = "labi8575_inventory";
$conn = mysql_connect($servername, $username, $password);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('labi8575_inventory');
$runs3 = $_POST["runs3"];
$sql = mysql_query("UPDATE demo SET runs3 = '$runs3'");
$retval = mysqli_query( $sql, $conn );
?>
问题是我无法将 var runs3 从 javascript 函数传递到 php 文件。我还尝试根据以下主题(使用 ajaxRequest.open 向 php 发送变量)解决方案,例如 ajaxRequest.open("POST", "runs3.php?variable="+runs3) 或 AjaxRequest.open("POST" , "runs3.php?myvar=runs3", true); 但就我而言,它不起作用。你知道我的情况有什么问题吗?感谢您的关注。