0
У меня есть служба может использовать локон PUT, чтобы изменить значение свойства:
curl -l -X PUT -d processed=1 "http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/update&id=1"
curl -l -X PUT -d processed=0 "http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/update&id=1"
Я хочу, чтобы реализовать его в Angularjs:
var url = "http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/update&id=" + id;
var data = { 'processed': processed } ;
console.log("debug", url);
console.log("debug", data);
$http.put(url, data)
.success(function (response)
{
console.log("debug",response);
});
Но Я получил следующие ошибки:
XMLHttpRequest cannot load http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/update&id=1. Invalid HTTP status code 405
Что я могу сделать? Спасибо ...
обновленный:
Проблема существует в ионной служить, когда я отладки в моем устройстве Android, код работает отлично:
$http({
method: 'PUT', // support GET, POST, PUT, DELETE
url: "http://e9049d9.tunnel.mobi/yii2-basic/web/index.php?r=duangorder/restorder/update&id=" + id,
data: 'processed=1',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
timeout: 30000, // timeout abort AJAX
cache: false
}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
console.log("success", data);
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.error("error", data);
});
405 означает, что метод не допускается - может быть, 'put' не реализован на стороне сервера? – rzysia
Привет, @rzysia, спасибо за ваши проблемы. put реализован на стороне сервера, я могу использовать curl для тестирования, это нормально. –
Ваша команда curl отправляет параметр запроса в тело, используя application/x-www-form-urlencoded, тогда как ваш JS-код отправляет объект JSON в тело. Код ошибки вводит в заблуждение, но это, вероятно, проблема. –