When is it appropriate to use AJAX?

2019-05-10 15:06发布

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 use AJAX if the situation was appropriate: Should I add AJAX logic to my PHP classes/scripts?

In response to Chad Birch's answer: Yes, I'm referring to when developing a "standard" site that would employ AJAX for its benefits, and wouldn't be crippled by its application. Using AJAX in a way that would kill search rankings would not be acceptable. So if "keeping the site intact" requires more work, than that would be a "con".

8条回答
乱世女痞
2楼-- · 2019-05-10 16:05

Javascript should always just be an addition to the functionality of your website. You should be able to use and navigate the site without any Javascript involved. You can use Javascript as an addition to existing functionality, for example to avoid full-page reloads. This is an important factor for accessibility. Javascript should never be used as the only possibility to reach or complete a request on your site.

As AJAX makes use of Javascript, the same applies here.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-05-10 16:06

Ajax gives you two big things:

Responsiveness - you can update only parts of a web page at a time if need be (saving the time to re-load a page). It also makes it easier to page data that is presented in a table for instance.

User Experience - This goes along with responsiveness. With AJAX you can add animations, cooler popups and special effects to give your web pages a newer, cleaner and cooler look and feel. If no one thinks this is important then look to the iPhone. User Experience draws people into an application and make them want to use it, one of the key steps in ensuring an application's success.

For a good case study, look at this site. AJAX effects like animating your new Answer when posted, popups to tell you you can't do certain things and hints that new answers have been posted since you started your own answer are all part of drawing people into this site and making it successful.

查看更多
登录 后发表回答