如果有人能够解释为什么我的Dialog'对话错误'没有解雇,我将不胜感激。在firebug中,响应正确显示并且没有错误。但由于某种原因,对话框没有响应它。非常感谢。
Firebug回复
{"boxerror":"Error","box":"191"}{"boxerror":"Error","box":"192"}
submitHandler: function ()
{
if ($("#USRboxint").valid() === true)
{
var data = $("#USRboxint").serialize();
$.ajax(
{
type: "POST",
url: "bintk.php",
data: data,
dataType: "json",
success: function (data)
{
if (data.boxerror == 'Error')
{
var messageOutput = '';
for (var i = 0; i < data.length; i++)
{
messageOutput += data[i].box + ' ';
}
var $dialogError = $('<div id="dialog-error"></div>').html('<br />Your New Intake of ' + messageOutput + ' was NOT SUBMITTED. You must enter a box number that is unique.<br />Thank you.');
$dialogError.dialog(
{
autoOpen: true,
modal: true,
title: 'New Intake Unsuccessfull',
width: 400,
height: 260,
draggable: false,
resizable: false,
buttons: {
Close: function ()
{
$(this).dialog("close");
}
}
});
}
else
{
var messageOutputs = '';
for (var i = 0; i < data.length; i++)
{
messageOutputs += data[i].box + ' ';
}
//console.log(messageOutputs);
//$("#USRaddbox").html("<div class='successMessage'>is a valid e-mail address. Thank you.</div>");
$("#USRboxint").get(0).reset();
var $dialogSuccess = $('<div id="dialog-success"></div>').html('<br />Your New Intake of ' + '<b><font color="green">' + messageOutputs + '</font></b>' + ' was successfully submitted.<br />Thank you.');
$dialogSuccess.dialog(
{
autoOpen: true,
modal: true,
title: 'New Intake successfull',
width: 400,
height: 200,
draggable: false,
resizable: false,
buttons: {
Close: function ()
{
$(this).dialog("close");
}
}
});
}
}
});
}
}
PHP代码
<?php
$boxerrortext = 'Error';
//$error = array();
$sname = mysql_real_escape_string(htmlspecialchars($_POST['box_add']));
$namearray = explode(',',$sname);
foreach ($namearray as $sname){
$sql = "SELECT * FROM temp WHERE item = '" . $sname . "'";
$result = runSQL($sql) or die(mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows > 0) {
//trigger_error('It exists.', E_USER_WARNING);
$error = array('boxerror'=>$boxerrortext, 'box'=>$sname);
$result = json_encode($error);
echo $result;
}
}
?>
答案 0 :(得分:1)
看起来你想要创建的div总是被添加到DOM中。 我愿意:
$("html").append("<div id='dialog-success' />");
var $dialogSuccess = $("#dialog-success");
$dialogSuccess.html('<br />Your New Intake of <b><font color="green">' + messageOutputs + '</font></b> was successfully submitted. <br />Thank you.');
然后继续使用您的代码。