ajax请求测试。我的问题是...... test.php 应该在服务器中的哪个位置才能被 url:"test.php" 找到?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<button type="button" onclick="create()">Click Me</button>
<script>
function create () {
$.ajax({
url:"test.php", //the page containing php script
type: "post", //request type,
dataType: 'json',
data: {reg: "success", name: "bnm", email: "lolo@gmail.com"}
success:function(result){
console.log(result.abc);
}
});
}
<script>
在服务器端 test.php 文件
$regstration = $_POST['reg'];
$name= $_POST['name'];
$email= $_POST['email'];
if ($registration == "success"){
// some action goes here under php
echo json_encode(array("abc"=>'successfuly registered'));
}
jeck猫