Ajax调用JS + PHP无法正常工作

时间:2015-12-26 17:46:52

标签: javascript php jquery ajax

Chrome控制台错误: POST http:// ******************** 500(内部服务器错误)

JS

$.ajax({
                    method: "POST",
                    url:"ajax.php",
                    data: {
                        x: x,
                        y: y
                    },
                    success:function(data){...}
                 });

PHP

<?php

date_default_timezone_set('Europe/Madrid');

$link = mysql_connect("*******", "*******", "******");
mysql_select_db("******") or die ("no database");


$name = $_POST['x'];
$score = $_POST['y'];

// Get the current date
$current_date = date('d-m-Y H:i:s');

$sqlCommand = "INSERT INTO hungry_bird (date_played, name, score)
               VALUES('$current_date ', '$name', '$score')";

$results = mysql_query($sqlCommand) or die (mysql_error());

mysql_close($link);


?>

知道可能是什么问题吗?感谢。

1 个答案:

答案 0 :(得分:1)

$link = mysqli_connect("*******", "*******", "******");
mysqli_select_db($link, "******") or die ("no database");
$name = $_POST['x'];
$score = $_POST['y'];
$sqlCommand = "INSERT INTO hungry_bird (date_played, name, score)
               VALUES('CURDATE()', '$name', '$score')";
$results = mysqli_query($link, $sqlCommand) or die (mysqli_error($link));
mysqli_close($link);