一、js:
- 要点:
- 完整代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="jquery.min.js"></script> </head> <body> <script> $.ajax({ ‘url‘:‘http://localhost/index.php‘, ‘data‘:{‘sex‘:‘male‘}, ‘beforeSend‘:function(xhr){ xhr.setRequestHeader(‘name‘,‘lee‘); xhr.setRequestHeader(‘sex‘,‘male‘); xhr.setRequestHeader(‘height‘,‘168‘); }, ‘success‘:function(data){ console.log(data); } }); </script> </body> </html>
二、php:
- 要点:
- 完整代码:
<?php header(‘Access-Control-Allow-Origin:*‘); header(‘Access-Control-Allow-Credentials: true‘); header(‘Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS‘); header(‘Access-Control-Allow-Headers:WWW-Authenticate,Authorization,Set-Cookie,X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version,name,sex,height‘); $header = apache_request_headers(); var_Dump($header);exit;
原文地址:http://blog.51cto.com/12173069/2066641
时间: 2024-10-30 07:39:42