表单操作在ajax和jQuery中提交?

时间:2016-02-04 20:26:09

标签: javascript php jquery html ajax

我创建了3个单选按钮:

Change Password - Change Name - Delete Account

当我选择其中一个时,它会向我显示一个表单,但是问题是当我开始点击显示表单上的提交按钮时,它会将我重定向到另一个页面,而不是我在动作属性上选择的页面形式

例如:

    <form action = 'forget_pass.php' method = 'POST'>

当我点击提交按钮时,它应该将我重定向到页面(forget_pass.php),但它会将我重定向到我目前正在处理的大项目中的另一个页面。

我的代码包含单选按钮:

<script>
function showUser(str) {
if (str == "") {
document.getElementById("results").innerHTML = "";
return;
} else { 
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("results").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_form.php?z="+str,true);
xmlhttp.send();
}
}
</script>

<form class = "form-horizontal">

<label><p style="color:red;">
<input type = "radio" name = "select" value = "pass"      onChange="showUser(this.value)"> Change Password

<input type = "radio" name = "select" value = "name" onChange="showUser(this.value)"> Change Name

<input type = "radio" name = "select" value = "account" onChange="showUser(this.value)"> Delete Account
</p></label>

</form>
<div id = "results"> </div>

我的代码显示了表单(get_form.php):

<?php
$z = $_GET['z'];
if($z == "pass")
{
   // form 
}
else if ($z == "account")
{
   // form
}

else if($z == "name")
{
   // form
}
?>

0 个答案:

没有答案