首页 \ 问答 \ AngularJS $ http.post返回状态0(AngularJS $http.post return status 0)

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
更新时间:2022-03-09 15:03

最满意答案

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 .someDiv{ color:#353535; } .someDiv span{ font-weight:bold; color:red; } HTML
    Hello World!
    任何使用'someDiv'的div内的span标签都会有红色+粗体文本。 CSS .someDiv{ color:#353535; } .someDiv span{ font-weight:bold; color:red; } ...
  • 您可以在给定的一组属性上指定多个选择器,如下所示: .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 ...
  • 使用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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)