1
我新的angularjs做一個CRUD我使用的功能,這將是使用兩個更新和保存我的功能碼
$scope.save = function (modalstate, id) {
var url = $scope.url;
var method = "POST";
console.log(modalstate);
//append id to the URL if the form is in edit mode
if (modalstate === 'edit') {
url += "/" + id;
method = 'PATCH';
}
var data = {};
data = $scope.formdata;
if (!$("#myform").isValid()) {
return false;
} else {
console.log('request');
$http({
method: method,
url: url,
data: data,
headers: {'Content-Type': undefined},
transformRequest: function (data) {
console.log(angular.toJson(data));
var formData = new FormData();
formData.append("data", [angular.toJson(data)]);
if (typeof (data.logo) != "undefined")
{
formData.append("file", data.logo);
}
console.log(formData);
return formData;
},
}).success(function (response) {
console.log(response);
// location.reload();
}).error(function (response) {
console.log(response);
alert('This is embarassing. An error has occured. Please check the log for details');
});
}
以上功能是完美的,當我存儲記錄。但在編輯的更新記錄我使用PATCH
請求,但現在通過使用PATCH
請求我收到了服務器端的空數組問題。請幫助我解決我的問題。
你能告訴我們你的'控制器\ action'並提供通路登錄 – xAoc
我只是用與資源路徑'路線::資源的代碼(」人」, '把PeopleController');' –