1. 程式人生 > >jquery的post方式傳送AJAX請求

jquery的post方式傳送AJAX請求

 1 <!DOCTYPE html>
 2 <html>
 3   <head>
 4     <meta http-equiv="content-type" content='text/html;charset=utf-8'>
 5     <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js" ></script>
 6     <title></title>
 7   </head>
 8   <body
> 9 <script> 10 $.post('./jquery_post.php',{os:'windows',code:'php'},function(data){ 11 alert(data.param1 + '------' + data.param2); 12 },'json'); 13 </script> 14 <h1 id='h1'></h1> 15 </body> 16 </html>
jquery_post.html
 1
<?php 2 $os=$_POST['os']; 3 $code=$_POST['code']; 4 echo json_encode( 5 array( 6 'param1'=>$os, 7 'param2'=>$code 8 ) 9 ); 10 ?>
jquery_post.php

 

 1 //判斷是否AJAX請求 2 isset($_SERVER['HTTP_X_REQUESTED_WITH']