我正在构建一个上传表单,用户可以在其中上传文档以及有关文档的详细信息,例如其名称等。我遇到的问题是,当用户使用选择选择类别时,我必须生成另一个选择,然后给出用户选择子类别的选项。请参阅以下内容:-
$(".department").change(function() {
var url = "includes/get-categories.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#upload-modal").serialize(), // serializes the form's elements.
success: function(data){
//this is where the select is generated
$(".sub").html(data); // show response from the php script.
//The alert works but the above line does not
alert("yeahhhhhhhhhhhhhhh boi");
}
});
Now this works like it should in that when the select is changed it generates another select from get-categories and gives the user another select box. 但是由于某种原因,当用户提交表单并在表单中显示错误列表(字段留空等)时,将不再通过选择类别来生成选择框。我什至用确实有效的警报测试了代码,所以我真的很困惑为什么以下行不起作用
$(".sub").html(data);
这是我的表格,非常标准
echo "<form enctype='multipart/form-data' action='".$_SERVER['PHP_SELF']."' method='POST' autocomplete='off' id='upload-modal'>";
echo '<fieldset>';
echo '<legend>Please fill in all the fields below:- </legend>';
echo '<label for="docname">Document name</label>';
echo '<input class="block" type="text" name="docname" id="docname" value="'.$_POST['docname'].'" />';
echo '<label for="version">Version (if left blank it will be entered as 1.0)</label>';
echo '<input class="block" type="text" name="version" id="version" value="'.$_POST['version'].'" />';
//We need to now give a drop down for the admin to select a department
try {
$conn = new PDO(DB_HOST,DB_USER,DB_PASS);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('SELECT X FROM Y WHERE Z = :id');
$stmt->execute(array('id' => A));
while($row = $stmt->fetch()) {
// if the user is an admin we provide them with the admin link
if($row['admin_level']=="super" || $row['admin_level']=="admin" && $row['department']=="Assurance" ){
echo '<select id="department" class="block department" name="department">';
echo '<option value="0">department...</option>';
echo '<option value="policies">Policies</option>';
echo '<option value="procedures">Procedures</option>';
echo '</select>';
}
echo '<p class="sub"></p>';
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
echo '<label for="keywords">Enter keywords (seperate with ",")</label>';
echo '<textarea id="keywords block" name="keywords" rows="4" cols="50" value="'.$_POST['keywords'].'"></textarea> ';
echo '<label for="filename">Supported formats - .docx & .pdf</label>';
echo '<input type="file" name="filename" id="filename" title="Supported formats - .docx and .pdf" />';
echo '<input class="submit-ie6" type="submit" name="submit" value="Upload" id="upload-modal-submit" />';
echo '</fieldset>';
echo '</form>';
任何帮助都是最受重视的