我一直在讨论这个问题。我有一个表单,我需要通过jquery提交,而无需重新加载页面。 ` 不知何故,除非我删除回调函数,否则表单将不会提交。但我还需要这个回调函数来防止表单重新加载。有什么好主意吗?感谢
<form id="myForm" method="post" action="some.php">
<input type="file" name="filename" />
<input type="button" id="button" />
</form>
<script>
$(document).ready(function(){
$(document).on("click", "#button", function(){
//Perform some operations then submit the form
$("#myForm").submit(function(e){ //Somehow, this part of the code is not running unless
e.preventDefault(); // I remove the callback function
alert("form submitted!"); // I also need the callback function to prevent page reloading
});
});
});
</script>
答案 0 :(得分:0)
<script type="text/javascript">
$(document).ready(function(){
$("#button").click(function(e){
e.preventDefault();
var site_url = "page url that you hope to load";
$("#content").load(site_url);//#content is that div your page'll be load
});
});
</script>
//try this one,