【发布时间】:2011-12-24 04:37:46
【问题描述】:
我正在使用 Jquery、Ajax 和 PHP 来尝试发送要写入 mysql 数据库的变量。 正在发出 Ajax 请求,但 php.ini 未获取该变量。我不知道为什么会这样。
使用 firebug 和 console.log() 我可以看到已经对 write_results.php 进行了 POST
如果我检查它说的响应
注意:未定义索引:E:\write_results.php 中的测试分数在 2
行这是我的 PHP
<?php
$testscore=$_POST['testscore']; //get testscore from Ajax
include 'DB.php';
$con = mysql_connect($host,$user,$pass);
$dbs = mysql_select_db($databaseName, $con);
if (isset($_POST['testscore'])) {
$addClient = "INSERT INTO variables (`id` ,`name`) VALUES (NULL,'$testscore')";
mysql_query($addClient) or die(mysql_error());
}
?>
这是我的 ajax 脚本
<script type="text/javascript">
$(document).ready(function() {
testscore ="tryagain"; //testvalue to enter into the mysql database
$.ajax({
type: "POST",
url: "write_results.php",
data: testscore,
success: function(){
$('#box2').html("success");
}
})
});
</script>
我的问题
- 为什么 $testscore 没有从 ajax 脚本接收值?
- 我该如何解决这个问题?
【问题讨论】:
标签: php jquery post undefined-index