我是php和javascript的新手......
我知道js是客户端n php是服务器端
但我想将变量x的值传递给$ res
我尝试使用AJAX,但我无法得到结果..
请帮助..
<SCRIPT LANGUAGE="JavaScript">
...
var x=0;
for (var i = 1; i < po; i++) {
if (Pr[i]['kRs'] == 'pSt') {
x++;
}
...
</SCRIPT>
<?php
$res=
$con = mysql_connect("localhost", "root", "root");
if (!$con) {
die("Database connection could not be established" . mysql_error());
}
$db_select = mysql_select_db("jaka", $con);
if (!$db_select) {
die("Database could not be selected" . mysql_error());
}
$bha=$_uid=$_SESSION['username'];
mysql_query("UPDATE user_info SET extra3='$res' WHERE username='$bha' ");
?>
答案 0 :(得分:0)
快速而肮脏的例子
your_page.html
_load_jQuery_here_
<SCRIPT LANGUAGE="JavaScript">
...
// your JavaScript code
$.ajax('saving_in_database.php?my_x=' + x);
...
</SCRIPT>
saving_in_database.php
<?php
$res = $_GET['my_x'];
// your PHP code
?>