我正在对服务器进行 ajax 调用以获取一些数据。
$.ajax(
{
url: "myserver",
method: "GET",
}.success(function(data)
{ }
.error(function(e)
{ }
)
我一直在阅读有关 .then() 的内容。
使用 .then() 相对于 .success() 是否有任何性能优势?
是否有任何特定场景我应该使用 .then() 和 .success()?
另外,无论谁回答,请简要介绍一下什么是 Promises。
最佳答案
您应该使用 then
,因为 success
和 error
已被弃用。
https://docs.angularjs.org/api/ng/service/ $http
The $http legacy promise methods success and error have been deprecated. Use the standard then method instead. If $httpProvider.useLegacyPromiseExtensions is set to false then these methods will throw $http/legacy error.
关于javascript - Angular 中 .success() 或 .then() 哪个更好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37392347/