在AngularJS中发送PUT请求可以使用$http服务。下面是一个示例代码:
$http({
method: 'PUT',
url: '/api/users',
data: { name: 'John', age: 30 }
})
.then(function(response) {
// 请求成功处理逻辑
console.log(response.data);
})
.catch(function(error) {
// 请求失败处理逻辑
console.error(error);
});
上面的代码中,我们使用了$http服务的method
参数设置为'PUT',url
参数设置为请求的URL,data
参数设置为要发送的数据。
在then
回调函数中处理请求成功的逻辑,可以通过response.data
访问返回的数据。
在catch
回调函数中处理请求失败的逻辑,可以通过error
参数获取错误信息。
注意:在发送PUT请求时,需要确保服务器端的接口支持PUT方法。