AngularJS $ http.post返回状态0(AngularJS $http.post return status 0)
我正在研究Ionic框架的角度js。 当我请求数据时,它总是返回状态0作为错误。 我认为问题是HTTP访问控制(CORS)。 但我已将Access-Control-Allow-Origin设置为* 。 我还需要做些什么? 请帮忙。 谢谢。
Angular JS代码
var params = { limit: 5, page: 1 }; $http.post('https://www.example.com/getdata.php', { params: params }) .success(function (data,status) { console.log("Conection available . Status s" + status); }) .error(function (data, status, headers, config) { console.log("Error Status " + status); });
返回标题
Access-Control-Allow-Origin → * Access-Control-Request-Headers → * Access-Control-Request-Method → POST Cache-Control → max-age=2592000 Connection → Keep-Alive Content-Length → 1933 Content-Type → application/json Date → Thu, 08 Sep 2016 06:47:31 GMT Expires → Sat, 08 Oct 2016 06:47:31 GMT Keep-Alive → timeout=5, max=100 Server → Apache/2.4.20 (Ubuntu)
UPDATE
所以浏览器日志的实际错误代码是
XMLHttpRequest无法加载https://www.example.com/getdata.php 。 请求标头字段在预检响应中,Access-Control-Allow-Headers不允许使用Content-Type。
我尝试更新Access-Control-Allow-Headers标头,如下所示。
$http.post('https://www.example.com/getdata.php', { params: params }, { 'Access-Control-Allow-Headers': 'application/json' })
并更新了响应标头,如下所示。
Access-Control-Allow-Headerss → application/json Access-Control-Allow-Origin → * Access-Control-Request-Headers → * Access-Control-Request-Method → POST Cache-Control → max-age=2592000 Connection → Keep-Alive Content-Length → 1933 Content-Type → application/json Date → Thu, 08 Sep 2016 07:22:03 GMT Expires → Sat, 08 Oct 2016 07:22:03 GMT Keep-Alive → timeout=5, max=100 Server → Apache/2.4.20 (Ubuntu)
但仍然没有运气。 请帮忙。
I'm working on Ionic framework's angular js. And when I request the data, it always return the status 0 as the error. I believe the issue is HTTP access control (CORS). But I already set Access-Control-Allow-Origin as *. What do I need to do more? Please help. Thank you.
Angular JS Code
var params = { limit: 5, page: 1 }; $http.post('https://www.example.com/getdata.php', { params: params }) .success(function (data,status) { console.log("Conection available . Status s" + status); }) .error(function (data, status, headers, config) { console.log("Error Status " + status); });
Return Header
Access-Control-Allow-Origin → * Access-Control-Request-Headers → * Access-Control-Request-Method → POST Cache-Control → max-age=2592000 Connection → Keep-Alive Content-Length → 1933 Content-Type → application/json Date → Thu, 08 Sep 2016 06:47:31 GMT Expires → Sat, 08 Oct 2016 06:47:31 GMT Keep-Alive → timeout=5, max=100 Server → Apache/2.4.20 (Ubuntu)
UPDATE
So the actual error code from browser log is
XMLHttpRequest cannot load https://www.example.com/getdata.php. Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.
And I tried updating Access-Control-Allow-Headers header as the following.
$http.post('https://www.example.com/getdata.php', { params: params }, { 'Access-Control-Allow-Headers': 'application/json' })
And updated the respond header as the following.
Access-Control-Allow-Headerss → application/json Access-Control-Allow-Origin → * Access-Control-Request-Headers → * Access-Control-Request-Method → POST Cache-Control → max-age=2592000 Connection → Keep-Alive Content-Length → 1933 Content-Type → application/json Date → Thu, 08 Sep 2016 07:22:03 GMT Expires → Sat, 08 Oct 2016 07:22:03 GMT Keep-Alive → timeout=5, max=100 Server → Apache/2.4.20 (Ubuntu)
But still no luck. Please help.
原文:https://stackoverflow.com/questions/39384682
最满意答案
CSS
.someDiv{ color:#353535; } .someDiv span{ font-weight:bold; color:red; }
HTML
<div class="someDiv"> Hello <span>World!</span> </div>
任何使用'someDiv'的div内的span标签都会有红色+粗体文本。
CSS
.someDiv{ color:#353535; } .someDiv span{ font-weight:bold; color:red; }
HTML
<div class="someDiv"> Hello <span>World!</span> </div>
Any span tag inside a div using 'someDiv' as it's class will have red + bold text.
相关问答
更多-
如果在tinyMCE init之后 您必须使用setContent()方法,以便设置完整内容 tinyMCE.activeEditor.setContent('My test!'); 或者如果你想只改变选定的部分 tinyMCE.activeEditor.selection.setContent('Some contents'); 如果在tinyMCE init之前 您可以直接设置HTML容器 $('textarea').text('My text!'); If af ...
-
有很多方法可以做到这一点。 选项1 - 修复收集集。 public class Header { private List
_lines public int HeaderId { get; set; } public List Lines { get { return _lines; } set { _lines = value; if(_lin ... -
您是指Visual Studio 2015/2017或VS Code? 当前版本的VS代码提供了灯泡图标,可以在VS 2015/2017中像使用C#一样完成导入语句。 Are you referring to Visual Studio 2015/2017 or VS Code? The current version of VS Code provides the lightbulb icon to complete the import statements for you just like with ...
-
CSS类重用/自动填充(CSS class reuse / auto populate)[2023-03-14]
CSS .someDiv{ color:#353535; } .someDiv span{ font-weight:bold; color:red; } HTMLHello World!任何使用'someDiv'的div内的span标签都会有红色+粗体文本。 CSS .someDiv{ color:#353535; } .someDiv span{ font-weight:bold; color:red; } ... -
在基于id的css中重用类(Reuse classes in an id based css)[2022-04-17]
您可以在给定的一组属性上指定多个选择器,如下所示: .LinkButton , #id1 { color: red; border: solid 1px blue; } /* Both get these */ #id1 { back-color: green; } /* Adding rules */ 如果您需要,它也可以覆盖任何属性: .LinkButton , #id1 { color: red; back-color: red; } /* Both get these */ #id1 { back ... -
填充自动增量(Populate Auto Increment)[2024-01-18]
使用row_number() over (order by (select null))可能有效,但我不认为顺序保证按插入顺序排列 - 如果未明确排序,则从select语句返回的数据表示无序集。 最佳解决方案是在插入时添加标识列或时间戳。 select * , r = row_number() over (order by (select null)) from #Test 或者您可以更改表以添加标识列,如下所示: alter table #test add id int identity(1,1) U ... -
您可以尝试向Brand类添加save方法。 from django.template.defaultfilters import slugify class Brand(models.Model): ... def save(self, *args, **kwargs): self.slug = slugify(self.brand_name) super(Brand, self).save(*args, **kwargs) 然后运行: python manage.py shell ...
-
没有什么可以阻止你编写自己的标记库来做到这一点。 但是, textField类的包含标记库没有此行为。 从文档中可以看出。 There is nothing stopping you from writing your own tag library to do just that. However the included tag libraries for such things as the textField do not have this behavior. As can be seen fro ...
-
使用Annotation的Java解决方案(数据建模包) 您可以使用DynamoDBAutoGeneratedTimestamp注释。 @DynamoDBAutoGeneratedTimestamp(strategy=DynamoDBAutoGenerateStrategy.CREATE) public Date getCreatedDate() { return createdDate; } public void setCreatedDate(Date createdDate) { this.creat ...
-
(没有涉及最佳实践的问题......) 你的第二个代码片段使用mysql_query()的返回值是有问题的。 PHP手册指出 : 对于SELECT,SHOW,DESCRIBE,EXPLAIN和其他返回结果集的语句,mysql_query()在成功时返回资源,如果出错则返回FALSE。 因此, $variable是一个PHP资源,不能等于字符串。 尽可能使用tripple === equals。 您仍然需要从结果资源“获取”记录(您设法在第一个代码段中执行此操作)。 一般来说 ... $result = my ...