当打开警告框时,它会自动关闭现有的打开对话框。我想确保在显示错误消息时对话框不会自动关闭。我尝试使用return false,但这不起作用 不知道我哪里错了。
<div id="dialog-form" title="Create new category">
<p class="validateTips">All form fields are required.</p>
<form>
<fieldset>
<label for="code">Code</label>
<input type="text" name="code" maxlength="9" id="code" value="" class="text ui-widget-content ui-corner-all"/>
<label for="name">Year</label>
<input type="text" name="name" id="name" maxlength="4" value=""
class="text ui-widget-content ui-corner-all" />
</fieldset>
</form>
</div>
$(function () {
var new_dialog = function (type, row) {
var dlg = $("#dialog-form").clone();
var year = dlg.find(("#acad_year")),
code = dlg.find(("#acad_code"));
type = type || 'Create';
var config = {
autoOpen: true,
height: 300,
width: 350,
modal: true,
buttons: {
"Create Academic Year": function () {
save_data("create");
},
"Cancel": function () {
dlg.dialog("close");
}
},
close: function () {
dlg.remove();
}
};
function save_data(strings) {
var id;
dlg.dialog("close");
if (strings == 'edit') {
id = $(row.children().get(0)).text();
} else {
id = "NU=L";
}
$.ajax({
url: 'acad_year.php',
type: 'post',
dataType: 'json',
data: {
id: id,
from: strings,
acad_year: year.val(),
acad_code: code.val()
},
success: function (response) {
if (response[0] === "REDUNDANT") {
alert("Data already exists. ");
}else if(response[0] === "EMPTY"){
alert("Data can't be left empty ");
} else {
sortTable(1);
$("#acodes tbody").append("<tr>" + "<td style='display:none;'>" + response[1] + "<td>" + year.val() + "</td>" + "<td>" + code.val() + "</td>" + "<td><a href='' class='edit'>Edit</a></td>" + "<td><span id='" + response[1] + "' class='delete'><a href=''>Delete</a></span></td>" + "</tr>");
}
},
error: function (error) {
alert("ERROR.." + error[0]);
}
});
}
};
答案 0 :(得分:0)
您可以编写错误消息,而不是警告错误。 例如:
<div id="a">
<div id="Error-msg" style="display:none;"></div>
...Some Form ....
</div>
</div>
<script>
if(error){
$("#Error-msg").append("<p>You have an error</p>");
}
</script>
而不是
error: function (error) {
alert("ERROR.." + error[0]);
}
您可以使用
error: function (error) {
$("#Error-msg").append("ERROR.." + error[0]);
}