使用jquery进行ajax调用的优缺点是什么? [英] what are the advantages and disadvantages of making ajax calls using jquery?

查看:55
本文介绍了使用jquery进行ajax调用的优缺点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于jquery ajax调用使生活真的很酷而无需刷新页面...但是仍然有兴趣了解使用jquery进行ajax调用的一些优缺点....

As jquery ajax calls makes life really cool without a page refresh... But still interested to know some of the advantages and disadvantages of making ajax calls with jquery....

由于我正在使用ajax调用我网站上的所有添加,编辑和删除"操作,因此到目前为止,它的运行情况还不错....仍然了解其缺点将使部署过程变得更轻松....

As i am using ajax calls for all my Add,Edit and Delete operations in my website it works pretty well as of now... Still knowing about the disadvantages would make life easier during deployment....

推荐答案

AJAX的最佳用途是用于发送小的有效负载.这是一个简单的例子.

The best use of AJAX is where it is used to send small payloads. Here is a simple example.

我加载了一个页面,其中包含有关库存的信息.它具有图形,图表,公司信息,还显示股价.每隔30秒,我会发出一个AJAX请求,以获取更新的股价并在页面上进行更改.

I load a page that contains information about stock. It has graphs, charts, company information and it also displays the share-price. Every 30 seconds, I make an AJAX request that gets the updated share-price and changes it on the page.

如果没有AJAX,我可能决定每30秒刷新一次整个页面,但是有了AJAX,我可以提出一个轻量级的请求,以获取我需要的一小部分信息.

Without AJAX, I might decide to refresh the entire page every 30 seconds, but with AJAX, I can just make a lightweight request to get the tiny bit of information I need.

使用AJAX提交表单并不总是最好的选择.除了不能真正给您提供比正常发布表单明显的优势,还破坏了诸如浏览器历史记录之类的约定(尽管某些浏览器现在将JavaScript状态"作为历史记录中的页面包含在内).

Using AJAX to submit forms isn't always the best bet. Asides from not really giving you a clear advantage over posting the form normally, you break conventions such as browser history (although some browsers now include JavaScript "states" as pages in the history).

使用AJAX时,您需要处理告诉用户是否出了问题的任务.您可以通过指定发生错误时应该使用jQuery来执行此操作,但是许多人忘记了执行此操作,最终用户非常高兴地没有意识到任何问题.

When using AJAX, you need to handle the task of telling the user if something has gone wrong. You can do this with jQuery by specifying what should happen on error, but many people forget to do this and the end user is blissfully unaware of any problem.

需要注意的其他问题是可能阻止事件触发的任何JavaScript错误-或者禁用了JavaScript,无论哪种情况,确保在添加AJAX代码之前可以正常提交表单都是最安全的选择.

Other issues to watch out for are any JavaScript errors that may prevent your events from firing - or if JavaScript is disabled, in either case ensuring that the form can submit normally before you add the AJAX code is the safest option.

这篇关于使用jquery进行ajax调用的优缺点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆