更新时间:2022-12-14 09:39:26
$http
用于通用 AJAX.在大多数情况下,这就是您将要使用的.使用 $http
,您将手动进行 GET
、POST
、DELETE
类型调用并处理对象他们自己回来.
$http
is for general purpose AJAX. In most cases this is what you'll be using. With $http
you're going to be making GET
, POST
, DELETE
type calls manually and processing the objects they return on your own.
$resource
包装 $http
以在 RESTful Web API 场景中使用.
$resource
wraps $http
for use in RESTful web API scenarios.
笼统地说:RESTful Web 服务将是一种具有一个数据类型端点的服务,该数据类型基于 GET
、POST等 HTTP 方法对该数据类型执行不同的操作code>、
PUT
、DELETE
等.所以使用$resource
,你可以调用GET
来获取资源作为 JavaScript 对象,然后更改它并使用 POST
将其发送回,甚至使用 DELETE
将其删除.
Speaking VERY generally: A RESTful web service will be a service with one endpoint for a data type that does different things with that data type based on HTTP methods like GET
, POST
, PUT
, DELETE
, etc. So with a $resource
, you can call a GET
to get the resource as a JavaScript object, then alter it and send it back with a POST
, or even delete it with DELETE
.
...如果这是有道理的.
... if that makes sense.