我在尝试实现AJAX Spinner加载代码时出于不明原因获取此错误.
我不明白应该在哪里定义标题.我做了,console.log(config)但我可以看到headers: accept: text/html那里的价值.
以下是我的代码:
/**
* Spinner Service
*/
//Spinner Constants
diary.constant('START_REQUEST','START_REQUEST');
diary.constant('END_REQUEST','END_REQUEST');
//Register the interceptor service
diary.factory('ajaxInterceptor', ['$injector','START_REQUEST', 'END_REQUEST', function ($injector, START_REQUEST, END_REQUEST) {
var $http,
$rootScope,
myAjaxInterceptor = {
request: function (config) {
$http = $http || $injector.get('$http');
if ($http.pendingRequests.length < 1) {
console.log(config);
$rootScope = $rootScope || $injector.get('$rootScope');
$rootScope.$broadcast(START_REQUEST);
}
}
};
return myAjaxInterceptor;
}]);
diary.config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push('ajaxInterceptor');
}]);
Run Code Online (Sandbox Code Playgroud) 下面是我遇到问题的代码:
//Main Codes for the Diary App
(function () {
//Create a new diary app
var diary = angular.module('diary', ['ngRoute']);
//Define a Router for the App
diary.config(function ($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'partials/wall.php',
controller: 'DiaryWallController'
}).
when('/images', {
templateUrl: 'partials/images.html',
controller: 'DiaryImagesController'
}).
when('/audio', {
templateUrl: 'partials/audio.html',
controller: 'DiaryAudioController'
}).
otherwise({
redirectTo: '/'
});
});
//Define Controllers
diary.controller('DiaryWallController', function($scope) {
$scope.message = "Lets do this!! Wall of this site";
});
diary.controller('DiaryImagesController', function($scope) {
$scope.message = "Lets do this!! Images …Run Code Online (Sandbox Code Playgroud) 当我通过AJAX发送POST请求时,我的Laravel POST路由返回405 GET方法.但是问题是它可以localhost在Heroku中工作但不能工作production server.我的AJAX POST请求作为GET请求发送到路由.下面我附上了截图和我的AJAX代码.
$.ajax({
url: url,
type: 'POST',
data: data,
contentType: 'application/json',
headers: {
'X-CSRF-TOKEN': token
}
})
Run Code Online (Sandbox Code Playgroud)
我的路线配置为:
Route::post('/adminpanel/projects/delete/', 'AdminPanelController@deleteData');
Run Code Online (Sandbox Code Playgroud)
我有一个从服务器端生成的对象数组,我想在 PHP 中过滤重复项...
\n\n下面是生成的数组
\n\narray:5 [\xe2\x96\xbc\n 0 => {#204 \xe2\x96\xbc\n +"category_name": "Fashion"\n +"category_id": "fashion"\n }\n 1 => {#205 \xe2\x96\xbc\n +"category_name": "Fashion"\n +"category_id": "fashion"\n }\n 2 => {#209 \xe2\x96\xbc\n +"category_name": "Shirts"\n +"category_id": "shirts"\n }\n 3 => {#210 \xe2\x96\xbc\n +"category_name": "Health"\n +"category_id": "health"\n }\n 4 => {#211 \xe2\x96\xbc\n +"category_name": "Shirts"\n +"category_id": "shirts"\n }\n]\nRun Code Online (Sandbox Code Playgroud)\n\n这里数组 0 和 1、数组 2 和数组 4 具有相同的值,如何过滤并仅获取现有数组或新生成的数组中的重复项的单个值。
\nangularjs ×2
javascript ×2
php ×2
ajax ×1
arrays ×1
filter ×1
heroku ×1
interceptor ×1
jquery ×1
laravel-5.1 ×1