我有以下调用另一个文件并根据下拉值吐出输出。它工作正常,但我似乎无法在没有提交按钮的情况下正常工作。这有效,除了它将自己重定向到process.php
正确的输出。这段代码的重点是在空的 div ( output
) 中显示输出。
$(document).ready(function() {
$('#dropdown').change( function() {
$('#myform').submit();
$.ajax({ // create an AJAX call...
data: $(this).serialize(), // get the form data
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
success: function(response) { // on success..
$('#output').html(response); // update the DIV
}
});
return false; // cancel original event to prevent form submitting
});
});
<form id="myform" method=POST action="process.php">
<select id="dropdown" name="dropdown">
<option value="QU">QU</option>
<option value="QF">QF</option>
<option value="QC">QC</option>
</select>
</form>
<div id="output"></div>