1 回答
TA贡献1772条经验 获得超6个赞
根据我的评论,我将使表单能够正常提交或使用 ajax 提交。Ajax进行搜索,正常提交下载:
<div class="container">
<!-- Make this a proper form tag again -->
<form id="ldap-form" method="post" action="working_csv.php">
<h2><strong><p>Search the LDAP server</p></strong></h2>
<label for="location"><p>Enter your search location (ex: dc=example,dc=com)</p></label>
<input type="text" id="location" name="location" placeholder="Search Location.." />
<label for="filter"><p>Enter your search filter(s) (ex: uid=* or </p></label>
<input type="text" id="filter" name="filter" placeholder="Filter(s).." />
<input type="submit" name="search" id="search" value="Search LDAP Server" />
<input type="submit" name="download" id="download" value="Download results as CSV file" />
</form>
<!-- Response container -->
<p id="msg"></p>
</div>
<script>
$(function(){
$('input[type="submit"]').on('click', function(e){
// Stop form from submission
e.preventDefault();
// Detect button press type
let thisSubmission = $(this).attr('name');
// If the button is search, do ajax
if(thisSubmission == 'search') {
$.ajax({
type: "post",
url: $('#ldap-form').attr('action'),
data: $('#ldap-form').serialize(),
cache: false,
success: function(html){
$('#msg').html(html);
}
});
}
else {
// Just submit the form normally
$('#ldap-form').submit();
}
});
});
</script>
- 1 回答
- 0 关注
- 131 浏览
添加回答
举报