views:

161

answers:

4

isnt it better to use jquery for form submit?

like:

    Username:
    <input type="text" id="username" name="username" maxlength="30" /><br />

    Password:
    <input type="password" id="password" name="password" maxlength="30" /><br />

    <input type="button" id="register" name="register" value="Register" />

and then bind the id="register" with jquery and when its click it gets the values of username and password with val()? then pass these values to php file with jquery ajax for the database job? this prevent the page to refresh and gives a more smooth web experience.

what do you think?

+1  A: 

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.

Jordan Ryan Moore
+1  A: 

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.

Guillaume Flandre
+1  A: 

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.

Miky Dinescu
+1  A: 

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.

ctford