亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

AngularJS POST失敗:飛行前響應具有無效的HTTP狀態代碼404

AngularJS POST失?。猴w行前響應具有無效的HTTP狀態代碼404

嗶嗶one 2019-10-19 14:14:52
我知道有很多這樣的問題,但是我所見的問題都沒有解決。我已經使用了至少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) {      console.log(status);    })    .error(function(data, status, headers, config) {      console.log('FAILED');    });  }});SlimPHP服務器:<?php    require 'vendor/autoload.php';    $app = new \Slim\Slim();    $app->response()->headers->set('Access-Control-Allow-Headers', 'Content-Type');    $app->response()->headers->set('Content-Type', 'application/json');    $app->response()->headers->set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');    $app->response()->headers->set('Access-Control-Allow-Origin', '*');    $array = ["response" => "Hello World!"];    $app->get('/get', function() use($array) {        $app = \Slim\Slim::getInstance();        $app->response->setStatus(200);        echo json_encode($array);    }); 我已啟用CORS,并且GET請求有效。html使用服務器發送的JSON內容進行更新。但是我得到了XMLHttpRequest無法加載http:// localhost:8080 / server.php / post。飛行前的響應具有無效的HTTP狀態代碼404每次我嘗試使用POST時。為什么?
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 917 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號