angularjs app

时间:2017-05-20 05:21:06

标签: angularjs

XMLHttpRequest无法加载domain.com/contact-form.php。对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许来源“domain.com:81”访问。

2 个答案:

答案 0 :(得分:0)

在所有代码之前将此标题添加到PHP文件中。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label>
  <input type="checkbox" name="chk[]" value='1'   />&nbsp;
  <input type="checkbox" name="chk[]" value='2'   />&nbsp;
</label>

希望它能解决问题。

答案 1 :(得分:0)

 app.config.js (your angular config file)

           $httpProvider.defaults.headers.post["Content-Type"] = 'text/plain';
           $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';

config.php (your php config file)
          header('Access-Control-Allow-Origin: *');
          header("Content-Type: text; charset=UTF-8");
          header("Access-Control-Allow-Methods: POST");
          header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
          ini_set('display_errors', 'On');
          error_reporting(1);
相关问题