【发布时间】:2014-06-11 01:07:10
【问题描述】:
我在 jQuery 文档中准备好了以下代码;
jQuery("#frmUpdateDet").submit(function (e) {
jQuery.ajax({
type: 'POST',
url: './php/updateCred.php',
data: jQuery(this).serialize(),
async: false,
success: function (data) {
jQuery("#msg").empty();
jQuery("#msg").append("<p>" + data + "</p>");
jQuery("#msg").show().delay(800).fadeOut();
}
});
e.preventDefault();
});
jQuery("#frmUpdatePass").submit(function (e) {
jQuery.ajax({
type: 'POST',
url: './php/updateCred.php',
data: jQuery(this).serialize(),
async: false,
success: function (data) {
jQuery("#msg").empty();
jQuery("#msg").append("<p>" + data + "</p>");
jQuery("#msg").show().delay(800).fadeOut();
}
});
e.preventDefault();
});
但是,当我提交“frmUpdateDet”表单时,它不会重定向到我的 php 脚本,但是当我提交“frmUpdatePass”表单时,它会重定向到我的 php 脚本……这怎么可能?我的函数只是前一个函数的复制品……
edit——我的两个 HTML 表单都是通过 JavaScript 添加的,其中一个表单如下所示—— 重新编辑...我的功能
function accountSettingMenuClick($id){
// 1 = details
// 2 = security
// 3 = cloud settings
jQuery("#AD").css("text-decoration", "none");
jQuery("#AS").css("text-decoration", "none");
jQuery("#ACS").css("text-decoration", "none");
var cred;
jQuery.ajax({
type: 'POST',
async: false,
url: './php/retrieve/getCred.php',
success: function (data) {
if (data != "null") {
cred = JSON.parse(data);
}
}
});
if($id == 1) {
jQuery("#AD").css("text-decoration", "underline");
var adHTML;
if(cred == "null") {
adHTML = "<p>Error! Contact Administrator</p>";
} else {
adHTML = "<form id='frmUpdateDet' action='./php/updateCred.php' method='POST'><table class='table'>" +
"<tr> <td>Name: </td> <td><input class='mainInput' name='name' type='text' value='" + cred['credentials']['name'] + "' placeholder='" + cred['credentials']['name'] + "'/></td> </tr>" +
"<tr> <td>Surname: </td> <td><input class='mainInput' name='surname' type='text' value='" + cred['credentials']['surname'] + "' placeholder='" + cred['credentials']['surname'] + "' /></td> </tr>" +
"</table> <table class='table'><tr><td><input type='submit' value='Update' class='mainBtn'/></td></tr></table> </form>";
}
jQuery("#content").append(adHTML);
} else if ($id == 2) {
jQuery("#AS").css("text-decoration", "underline");
var asHTML;
if(cred == "null") {
asHTML = "<p>Error! Contact Administrator</p>";
} else {
asHTML = "<form id='frmUpdatePass' action='./php/updateCred.php' method='POST'><table class='table'>" +
"<tr> <td>Old Password: </td> <td><input class='mainInput' name='oldPass' type='password' placeholder='Current Password' required/></td> </tr>" +
"<tr> <td>New Password: </td> <td><input class='mainInput' name='newPass' type='password' placeholder='New Password' required onchange='form.rPass.pattern = this.value;'/></td> </tr>" +
"<tr> <td>Re-type New Password: </td> <td><input class='mainInput' id='rPass' type='password' placeholder='Re-type New Password' /></td> </tr>" +
"</table> <table class='table'><tr><td><input type='submit' value='Update' class='mainBtn'/></td></tr></table> </form>";
}
jQuery("#content").append(asHTML);
} else if ($id == 3) {
jQuery("#ACS").css("text-decoration", "underline");
var acsHTML;
if(cred == "null") {
acsHTML = "<p>Error! Contact Administrator</p>";
} else {
var show;
var limit = cred['credentials']['limit'];
if (limit > 5000) {
show = limit/1024;
show = show.toFixed(2);
show = show + " GB";
} else {
show = limit;
show = show + " MB";
}
acsHTML = "<form id='frmUpdateUpg'><table class='table'>" +
"<tr> <td>Current Limit: </td> <td><input type='text' class='mainInput' style='border: none; border-bottom: 1px dashed black; width: 100px; text-align: center;' disabled value='" + show +"'></td> </tr>" +
"</table> <table class='table'><tr><td><input type='submit' class='mainBtn' value='Upgrade'/></td></tr></table> </form>";
}
jQuery("#content").append(acsHTML);
}
}
还有我的角度控制器 -
function AppSettingsCtrl($scope){
if (checkSession() == false){
location = "#/";
} else {
validateUI();
}
accountSettingMenuClick(1);
jQuery(document).ready(function (jQuery) {
jQuery("#AD").click(function () {
jQuery("#content").empty();
accountSettingMenuClick(1);
});
jQuery("#AS").click(function () {
jQuery("#content").empty();
accountSettingMenuClick(2);
});
jQuery("#ACS").click(function () {
jQuery("#content").empty();
accountSettingMenuClick(3);
});
jQuery("#frmUpdateDet").submit(function (e) {
jQuery.ajax({
type: 'POST',
url: './php/updateCred.php',
data: jQuery(this).serialize(),
async: false,
success: function (data) {
jQuery("#msg").empty();
jQuery("#msg").append("<p>" + data + "</p>");
jQuery("#msg").show().delay(800).fadeOut();
}
});
e.preventDefault();
});
jQuery("#frmUpdatePass").submit(function (e) {
jQuery.ajax({
type: 'POST',
url: './php/updateCred.php',
data: jQuery(this).serialize(),
async: false,
success: function (data) {
jQuery("#msg").empty();
jQuery("#msg").append("<p>" + data + "</p>");
jQuery("#msg").show().delay(800).fadeOut();
}
});
e.preventDefault();
});
});
}
【问题讨论】:
-
控制台出错?您可以发布其余的代码,包括 HTML 吗?
-
我的控制台没有错误
-
一般提示:如果您必须在字符串中使用 HTML(强烈建议将其存储在虚拟的
script元素模板中),请在外部使用单引号,以便 HTML 属性可以使用标准双引号. -
两种表单是否都添加/放置在 处理程序代码运行之前?
-
请同时显示第二个表单的 HTML。第一个看起来不错。
标签: javascript php jquery