ajax 触发preflight的配置
2017-07-09 12:31
127 查看
ajax 触发prefight的配置
Here’s sample code for making a CORS request with JQuery. The comments give more details on how certain properties interact with CORS.$.ajax({ // The 'type' property sets the HTTP method. // A value of 'PUT' or 'DELETE' will trigger a preflight request. //如果请求的方法是'put','delete',会触发preflight type: 'GET', // The URL to make the request to. url: 'http://html5rocks-cors.s3-website-us-east-1.amazonaws.com/index.html', // The 'contentType' property sets the 'Content-Type' header. // The JQuery default for this property is // 'application/x-www-form-urlencoded; charset=UTF-8', which does not trigger // a preflight. If you set this value to anything other than // application/x-www-form-urlencoded, multipart/form-data, or text/plain, // you will trigger a preflight request. //如果content-type的值不是默认的'application/x-www-form-urlencoded',会触发preflight contentType: 'text/plain', xhrFields: { // The 'xhrFields' property sets additional fields on the XMLHttpRequest. // This can be used to set the 'withCredentials' property. // Set the value to 'true' if you'd like to pass cookies to the server. // If this is enabled, your server must respond with the header // 'Access-Control-Allow-Credentials: true'. withCredentials: false }, headers: { // Set any custom headers here. // If you set any non-simple headers, your server must include these // headers in the 'Access-Control-Allow-Headers' response header. }, success: function() { // Here's where you handle a successful response. }, error: function() { // Here's where you handle an error response. // Note that if the error was due to a CORS issue, // this function will still fire, but there won't be any additional // information about the error. } });
原文链接 https://www.html5rocks.com/en/tutorials/cors/
相关文章推荐
- Moss2007配置--AJAX支持
- AJAX请求 $.ajaxSetup方法的使用:设置AJAX请求的默认参数选项,当程序中需要发起多个AJAX请求时,则不用再为每一个请求配置请求的参数
- MVC设计模式 (1)、html页面事件触发ajax()方法调用ajax.js发送请求至请求目标文件
- STM32F0 定时器触发ADC,多通道采样、DMA传输数据的配置
- IOS 项目里面必要配置button 不能同时触发点击事件
- 了解 ASP.NET AJAX 验证和配置文件应用程序服务(三)
- spring mvc ajax jsonp 跨域请求 返回值 配置
- ajaxToolkit:AutoCompleteExtender 的触发选择事件以及JSON序列化和使用键值对
- ajax控件无法使用 iis配置及web修改
- AJAX触发aspnet控件的C#事件(基于Jquery)
- ajax和json的post和get请求参数配置
- AjaxControlToolkit 配置
- MOSS2007支持AJAX的配置
- 简化 Ajax 和 Java 开发,第 2 部分:使用约定最小化设置和配置
- quartz中触发时刻cronExpression的配置说明
- Ajax跨域Post方法调用Web Api(NuGet配置的环境)
- Ajax基础配置 — XMLHttpRequest
- 关于Ajax的web配置
- 服务端配置实现AJAX跨域请求
- Quartz的配置及使用和定时触发功能的实现