【问题标题】:Angular js http request phpAngular js http请求php
【发布时间】:2015-12-31 21:12:36
【问题描述】:

我正在尝试将 Angular js 上的表单数据发送到 php 页面。但它不工作。 这是我的表格:

这是我的 $http 请求

    nodes.controller("addNew",function($http){
    var  content = this;

    this.submitNew = function(type)
    {
        //content.body.filter
       $http({method:'POST',url:http+'nodes/create',

               data:{
                   title:content.title,
                   author:content.author,
                   node_author:content.node_author,
                   body:content.body,
                   type:type
               },
               headers:{
                   "Access-Control-Allow-Methods":"POST",
                   'Content-Type': 'application/x-www-form-urlencoded',
                   'Access-Control-Allow-Origin':'*',
                   "Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
               }
           }

       );
        this.title = '';
        this.author = '';
        this.body = '';

    }
});

这个错误!!!

XMLHttpRequest cannot load http://hangoma.lc/nodes/create. Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers

标题详细信息

Remote Address:127.0.0.1:80
Request URL:http://hangoma.lc/nodes/create
Request Method:OPTIONS
Status Code:200 OK

请帮忙!!!我找不到解决办法。

【问题讨论】:

    标签: javascript php angularjs http xmlhttprequest


    【解决方案1】:

    当您尝试从127.0.0.1http://hangoma.lc/nodes/create 发出请求时。但是远程服务器不允许来自其他服务器的连接(http://hangoma.lc 除外)。

    您尝试连接的服务器应包含access-control- 标头。您不能从您的请求中强制执行这些操作。

    This问题有更多细节。

    【讨论】:

      猜你喜欢
      • 2016-08-11
      • 2016-11-15
      • 2019-08-05
      • 2017-01-06
      • 2018-02-15
      • 2023-03-03
      • 2015-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多