# Ajax请求怎么样才能在前端弹出错误提示？

**URL:** <https://meta.discourse.org/t/ajax/395532>\
**Category:** Development\
**Created:** [2026年二月9日 10:14 UTC](https://meta.discourse.org/t/ajax/395532 "2026-02-09T10:14:54Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)\
**Post date:** [2026年二月9日 10:27 UTC](https://meta.discourse.org/t/ajax/395532/2 "2026-02-09T10:27:18Z")

</div>

我不确定完整的上下文是什么，但我认为你可以这样做：

```js
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";

try {
  // ...
} catch (e) {
  popupAjaxError(e);
}

// 或者
ajax("...") // 某个函数
  .then(() => {
    // ...
  })
  .catch(popupAjaxError);

```

---

_[View the full topic](https://meta.discourse.org/t/ajax/395532)._
