我有一个这样的 html 表单:
<form method="post" action="https://serviceURL/">
<input name="account" ng-value="form.account" type="hidden">
<input name="name" ng-value="form.name" type="text">
<button type="submit">Continue</button>
</form>
当我提交表格时,一切都很完美。但是当我尝试在 Angular 服务中执行相同的发布请求时,我得到了
cannot load https://serviceURL/ Response for preflight has invalid HTTP status code 504
我的服务函数是这样的
service.callServer =function(){
var query = "https://serviceURL/";
$http.post(query,{account:123,name:'jhon'});
}
我的问题是:这些类型的请求有什么区别? html 操作帖子是否添加了一些 http.post 没有的标题?
最佳答案
这很可能是因为 CORS . Ajax 请求不能提交给您所在域以外的域,除非服务器设置 Access-Control-Allow-Origin
header 指定您的域。为了验证这一点,浏览器首先发送 preflight
OPTIONS 请求,您的服务器似乎对该请求作出错误响应。这不适用于提交 html 表单,因为它不是 AJAX 请求。
关于javascript - html post 和 js http.post 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40427927/