开发者

ajax and no forms, what will happen?

I notice my site does not have a single <form> with the exception of logging in. I am not sure how or why it happened but i found i use jquery and ajax to post everything then refresh (or not if i dont need to). How and why would the user suffe开发者_如何学Gor from this?

Some of my 'forms' include

  1. Leaving a comment on a page
  2. Removing messages
  3. Sending a private message (which i then do document.location=nextPage)
  4. Marking as a favourite.


Forgetting for a moment that none of the site would work without javascript disabled, another side effect you might not realize, is that there is no default submit behavior anymore. This means a user cannot finish typing their entry and hit enter to submit the form. This is important for search forms and the like, but less important for comment forms.

Wrapping form fields in a form tag and having a submit input element (even if it is display:none) allows for a default submit action on enter or return. If you do this, you simply call preventDefault() into the submit() event handler to stop the real submit, and make an AJAX one instead.

Ok, back to the JS disabled thought. You have to make a choice:

  1. Work backwards to implement unobtrusive JS on your site. Basically, the site works with or without JS, but it will work better (or more refined) with JS enabled
  2. Or place a prominent message alerting your users to the fact that your site requires JS for the site to work. The cons to this method is you might limit the usefulness of your site in some corporate networks and on some mobile devices. As far as people who willingly turn of JS, the alert can let them decide if they want to stay around or not.

Given that the site is already coded, take a look at your target audience and make your best decision given the time and energy required to make the site work without JS.


From your comment, I see that you don't intend to support users without JavaScript, so the accessibility and backward compatibility argument is moot.

However, you are likely creating a lot of unnecessary requests by posting with AJAX and then refreshing the page. This is not how AJAX was intended to be used and is possibly an anti-pattern. The idea of AJAX is to send specific and receive specific data, and to update the page based on that received data, not refreshing.

Also, by not using form's, you disable the default submit functionality (pressing <enter>) as Doug Neiner pointed out

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜