Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“选项请求返回”;否';访问控制允许原点';标题“;ajax发布到其他域时出错_Ajax_Angularjs_Post_Cors - Fatal编程技术网

“选项请求返回”;否';访问控制允许原点';标题“;ajax发布到其他域时出错

“选项请求返回”;否';访问控制允许原点';标题“;ajax发布到其他域时出错,ajax,angularjs,post,cors,Ajax,Angularjs,Post,Cors,我正在为CORS问题挣扎。我从js向另一个域发出请求,该方法允许跨域请求,并且在GET请求中一切正常,但在POST请求中则不行。看起来像是在POST之前调用了OPTIONS方法,并返回标准错误 请求的资源上不存在“Access Control Allow Origin”头。起源'http://localhost:3000因此,不允许访问。 return Response.ok().entity(c).header(“访问控制允许源代码”,“*”) .header(“访问控制允许方法”、“获取、发

我正在为CORS问题挣扎。我从js向另一个域发出请求,该方法允许跨域请求,并且在GET请求中一切正常,但在POST请求中则不行。看起来像是在POST之前调用了OPTIONS方法,并返回标准错误

请求的资源上不存在“Access Control Allow Origin”头。起源'http://localhost:3000因此,不允许访问。

return Response.ok().entity(c).header(“访问控制允许源代码”,“*”)
.header(“访问控制允许方法”、“获取、发布、删除、放置、选项”)
.header(“访问控制允许标头”、“内容类型、x-xsrf-token、x-Requested-With、Accept、Expires、Last Modified、Cache Control”).build();

在客户端,我使用angularjs

$http.post(url,数据).success(…)

但是也试过了

$.ajax({type:'POST',
标题:{
“接受”:“应用程序/json”,
“内容类型”:“应用程序/json”
}…})


同样的结果。我还可以做些什么来修复POST请求

将以下代码添加到Angular JS应用程序配置文件中

$httpProvider.defaults.useXDomain=true


删除$httpProvider.defaults.headers.common['X-Requested-With']

将以下代码添加到Angular JS应用程序配置文件中

$httpProvider.defaults.useXDomain=true

删除$httpProvider.defaults.headers.common['X-Requested-With']