$.ajax 设置header Access-Control-Allow-Origin
时间: 2023-10-07 11:10:41 浏览: 122
通过设置 $.ajax 的 header ,可以设置 Access-Control-Allow-Origin。这个头部字段用于指定允许跨域请求的域名。如果你想允许任何域名跨域访问,可以使用通配符 * ,即 Access-Control-Allow-Origin: * 。如果你只想允许特定的域名跨域访问,可以将 Access-Control-Allow-Origin 的值设置为该域名,如 Access-Control-Allow-Origin: http://www.client.com。此外,还可以通过设置其他相关的响应头部字段来进一步控制跨域访问,比如 Access-Control-Allow-Methods 来指定允许的请求方法,如 POST, Access-Control-Allow-Headers 来指定允许的请求头部字段,如 x-requested-with 和 content-type。这样就可以实现使用 $.ajax 进行跨域的 POST 请求了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Allow-CORS_-Access-Control-Allow-Origin_v0.1.2.crx](https://download.csdn.net/download/chen_chen11112/12195201)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [ajax 设置Access-Control-Allow-Origin实现跨域访问](https://blog.csdn.net/weimjay/article/details/60144358)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文