When is it appropriate to use AJAX?

前端 未结 8 1474
生来不讨喜
生来不讨喜 2021-01-06 09:24

When is it appropriate to use AJAX?
what are the pros and cons of using AJAX?

In response to my last question: some people seemed very adamant that I should only

8条回答
  •  南笙
    南笙 (楼主)
    2021-01-06 10:04

    When you are only updating part of a page or perhaps performing an action that doesn't update the page at all AJAX can be a very good tool. It's much more lightweight than an entire page refresh for something like this. Conversely, if your entire page reloads or you change to a different view, you really should just link (or post) to the new page rather than download it via AJAX and replace the entire contents.

    One downside to using AJAX is that it requires javascript to be working OR you to construct your view in such a way that the UI still works without it. This is more complicated than doing it just via normal links/posts.

提交回复
热议问题