开发者

better to use jquery on form submit button? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 6 years ago.

Improve this question

Is it better to use JQuery for form submission? For example:

<input type="text" id="username" name="username" maxlength="30" /><br />
<input type="password" id="password" name="password" maxlength="30" /><br />
<input type="button" id="register" name="register" value="Register" />

I could bind id="register" with JQuery and then get the values of username and password with val(); when it's clicked and pass them onto a PHP file for a database qu开发者_开发问答ery with AJAX - this would prevent the page refreshing and makes the user experience more smooth.

Do you agree?


This really depends on your specific scenario. If you're going to be redirecting the user to a different page once they've registered, then it makes no sense to use AJAX.


So what you're actually saying is whether or not using AJAX.

It really is up to what you're looking to do. It can be a good idea if this way you don't have to reload a whole page; but it really is up to you.

On a register page, if the only thing displayed is the registration form, it would be better not to use AJAX. it wouldn't make sense since the whole page has to be reloaded after submitting (again it depends on the scenario).

jQuery has nothing to do with it. In your case the issue is that if one doesn't have javascript activated, they won't be able to register.

You still can use a classic and this kind of javascript:

$("#register").click(function(e){
  e.preventdefault();
 // then perform your AJAX submission
});

This way, if javascript's not activated, you still can add a classic post submission and register the user.


Better? In what way? It's certainly possible and definitely not new, maybe better - maybe not. I'm not sure what your trying to find out.. Whether it is safe? It can be if done right. But you have to be more specific.

There is a lot of information on the internet on the debate around what AJAX does for the web user experience and opinions are split on both sides.


There is one big limitation with using javascript - the browser's security model. URLs beginning with "http:" count as a different domain as "https:". That means that you can't send credentials over https if the user is currently on a plain http page.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜