Sunday 15 August 2010

javascript - Confused about the action tag -



javascript - Confused about the action tag -

i've got html page form set follows:

<form name="form" action="process.php" method="post"> username: <input type="text" name="user"> <br> password: <input type="text" name="pass"> <br> <input type="submit" value="login"> </form>

when click submit button, info sent process.php script, , that's , good.

but i'd send json string php script instead, , have php script parse it. such tried following:

<body> please come in information: <form name="form" action=""> username: <input type="text" name="user"> <br> password: <input type="text" name="pass"> <br> <input type="submit" value="login" onclick="encrypt(this.form, 0)"> </form> </body> <script language="javascript"> function encrypt(form, key){ var user = form.user.value; var pass = form.pass.value; var str = {"username": user, "encrypted_password": pass}; var json_str = json.stringify(str); var xhr = new xmlhttprequest(); xhr.open("post", "process.php", true); xhr.send(json_str); } </script>

yet doens't anything. when click submit button nil happens. if process.php display when click submit button, enormously helpful.

thanks!

if want utilize onclick event need replace submit button.

<input type="button" value="login" onclick="encrypt(this.form, 0)">

and submit form javascript.

javascript php html forms post

No comments:

Post a Comment