-2
的index.html我的AJAX不工作
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="jquery-3.1.0.min.js" type="text/javascript"></script>
<script src="myValidations.js" type="text/javascript"></script>
</head>
<body>
Username : <input type="text" id="txtusername"></>
Password : <input type="text" id="txtpassword"></>
<input type ="submit" value="Save" id="btnSave"></>
<div id="disp"></div>
</body>
</html>
myValidation.js
$(document).ready(function(){
$("#btnSave").click(function() {
var username = $("#txtusername").val();
var password = $("#txtpassword").val();
$.ajax({
type: 'POST',
url: 'savecontacts.php',
data: {user:username, pass:password},
success: function (data) {
alert(data);
}
});
});
});
savecontacts.php
<?php
require_once './connectDB.php';
$user = $_POST("user");
$pass = $_POST("pass");
mysqli_query($conn, "insert into tbluser (username, password) values ('$user','$pass')");
echo "Done!";
?>
我的问题是 - 它不工作。它不执行php函数。有人对此有所了解吗?我是这种类型的编程的新手。我是一名桌面开发人员,现在我正在从事网络编程。
感谢
什么是不工作? – Phiter
Javascript控制台中的任何错误? – Barmar
另外你不用圆括号访问数组,你可以使用方括号。 '$ _POST [''];' – Phiter