对于ajax请求
原文链接:https://www.f2er.com/ajax/159951.html1.在您的网页中包含Jquery库.
例如:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<button type="button" onclick="create()">Click Me</button>
3.点击按钮,在javascript中调用create function.
<script> function create () { $.ajax({ url:"test.PHP",//the page containing PHP script type: "post",//request type,dataType: 'json',data: {registration: "success",name: "xyz",email: "abc@gmail.com"} success:function(result){ console.log(result.abc); } }); } <script>
在服务器端test.PHP文件中,应该读取动作POST参数和相应的值并在PHP中执行操作并以json格式返回,例如:
$regstration = $_POST['registration']; $name= $_POST['name']; $email= $_POST['email']; if ($registration == "success"){ // some action goes here under PHP echo json_encode(array("abc"=>'successfuly registered')); }