小编Dee*_*riz的帖子

AngularJS POST失败:预检的响应具有无效的HTTP状态代码404

我知道有很多这样的问题,但我见过的都没有解决我的问题.我已经使用过至少3个微框架.所有这些都在进行简单的POST时失败,这应该返回数据:

angularJS客户端:

var app = angular.module('client', []);

app.config(function ($httpProvider) {
  //uncommenting the following line makes GET requests fail as well
  //$httpProvider.defaults.headers.common['Access-Control-Allow-Headers'] = '*';
  delete $httpProvider.defaults.headers.common['X-Requested-With'];
});

app.controller('MainCtrl', function($scope, $http) {
  var baseUrl = 'http://localhost:8080/server.php'

  $scope.response = 'Response goes here';

  $scope.sendRequest = function() {
    $http({
      method: 'GET',
      url: baseUrl + '/get'
    }).then(function successCallback(response) {
      $scope.response = response.data.response;
    }, function errorCallback(response) { });
  };

  $scope.sendPost = function() {
    $http.post(baseUrl + '/post', {post: 'data from client', withCredentials: true })
    .success(function(data, status, headers, config) …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax cors angularjs

58
推荐指数
2
解决办法
17万
查看次数

标签 统计

ajax ×1

angularjs ×1

cors ×1

javascript ×1

php ×1