专业提示和技巧
我正在尝试通过在许多网站上找到的不引人注目但非常有用的改进来提高我的网络编程技能。 Stackoverflow.com 就是其中之一。当我提出问题时,页面会提交问题,并且我的浏览器会重新加载并显示我的问题。我的后退按钮正常工作,而不是(从用户的角度)问我“为了显示此页面,我们需要将您的请求重新发送到服务器。您想这样做吗?”这个可怕的问题。
此外,提交问题后,如果我点击“刷新”,它也不会调用另一个表单提交。
有没有一个网站列出了类似的技巧?我假设我将不得不重新考虑我最常使用的标准显示/提交/显示周期,但我非常愿意学习一些新技术。
有人给我指点一下吗?
编辑:我想我应该在这里说这一点,而不是在个人评论中。 Firebug 确实是一个很棒的工具,我一直在使用它。这些天我越来越多地使用 jQuery,但我很难称自己精通它。我很想使用 Firebug 来跟踪提问、评论等时发生的情况,但我不想出于学习目的而滥用该网站。 ;)
I'm trying to polish my web programming skills with the unobtrusive yet extremely helpful polish I find on many sites. Stackoverflow.com, for one. When I ask a question, the page submits the question, and my browser reloads itself displaying my question. My back button works like it really should, not asking me (from a user's perspective) the scary question of "In order to display this page we need to resend your request to the server. Do you want to do that?"
In addition, after submitting the question, if I hit "refresh" it also doesn't call another form submit.
Is there a site that lists out tricks like this? I'm assuming that I'm going to have to rethink the standard display/submit/display cycle that I use most often, but I'm very willing to learn some new techniques.
Anyone have any pointers for me?
EDIT: I figured I'd say this here instead of in individual comments. Firebug is indeed a fantastic tool, and I use it all the time. I'm using jQuery more and more these days, but I'd hardly call myself proficient at it. I'd love to use Firebug to track what happens when asking questions, commenting, etc, but I don't want to abuse the site for the purposes of learning. ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您所指的很多内容都是由于 AJAX 的使用越来越多互联网。表单在后台使用 AJAX 提交,页面动态更新,无需实际重新加载。由于它不是通过传统表单提交的,因此页面上没有 POST 请求,这就是导致您所指的重新提交的原因。查看Unobtrusive Javascript、行为分离并使用jQuery,你会发现它是多么容易就是为了完成这种类型的功能。
A lot of what you're referring to is due to the increasing use of AJAX throughout the internet. Forms are submitted using AJAX behind the scenes and the page is updated dynamically without actually reloading. Since it wasn't submitted via a traditional form, there is no POST request on the page, which is what causes the re-submit you're referring to. Look into Unobtrusive Javascript, Behavioral Separation and use jQuery and you'll find how easy it is to accomplish this type of functionality.
为了向您的站点添加光滑的非重新加载层,需要进行大量的 ajax 操作。但是,如果您不想深入了解 ajax,还有一种简单的方法,可以在提交表单后重定向 url。这意味着浏览器可以刷新等,并且不会重新提交。
至于列出此类推荐的单个网站,我一时不知道,但有兴趣看看人们是否可以推荐任何好的网站
There is alot of ajax being done to add a slick non reloading layer to your site. But if you do not want to go that deep into ajax there is also the simple method of redirecting the url after you have submited the form. This will mean the browser can be refreshed etc and it will not resubmit.
As for a single site listing these kinds of recommendations, I do not know of one off hand but would be interested to see if there are any good ones people can recommend
我不知道有哪个来源可以提供这样的信息,至少比这个网站更好。我认为网络编程有太多的方法可以做某事,有时 CMS 使事情变得顺利,有时是库,有时是手写代码。
我发现专注于较小范围的技术可以让我更轻松地构建一套个人的“最著名的方法”。
I don't know of one single source for info like this, better than this site at least. I think that with web programming there are simply too many ways to do something, sometimes the CMS makes things smooth, sometimes a library, sometimes hand written code.
I've found focusing on a narrower set of technologies allows me to build a personal set of "best known methods" easier.
打开 firebug 的网络选项卡总是很有用,可以查看引起您注意的网站中发生的情况。
It is always useful to open the network tab of firebug to see what's going on in the sites that catch your attention.