I have a form that submits just fine, but when I add jQuery code to show a loading div using spin.js everything stops working.
我有一个提交的表单很好,但是当我添加jQuery代码以使用spin.js显示加载div时,一切都停止工作。
<form id="search_form" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<!-- Form inputs here -->
...
<input id="exam_search" type="submit" name="submit" value="Search" />
Once I add the following code the form stops submitting and nothing happens. The loading div shows for a brief moment and then goes away like expected, but it seems like the form isn't actually submitting anymore.
一旦我添加以下代码,表单停止提交,没有任何反应。加载div显示一个短暂的时刻然后像预期的那样消失,但似乎表单实际上不再提交了。
var opts = // Array of options
var spinner = null;
$("#search_form").submit(function() {
spinner_div = document.getElementById('spinner');
if(spinner == null) {
spinner = new Spinner(opts).spin(spinner_div);
$("#search_results, #query").css({"opacity": "0.75"});
$("#search_form :input").attr("disabled", true);
} else {
spinner.spin(spinner_div);
$("#search_results, #query").css({"opacity": "0.75"});
$("#search_form :input").attr("disabled", true);
}
});
If I change all of that code in the submit event to this:
如果我将提交事件中的所有代码更改为:
$("#search_form").submit(function() {
alert ("form submitted");
});
It shows the alert and then returns the results of the form submission just fine.
它显示警报,然后返回表单提交的结果就好了。
What am I doing wrong here?
我在这做错了什么?
EDIT I saw in the jQuery docs for submit() that I shouldn't use the name "submit" on the input field. I tried changing that as well with no luck.
编辑我在jQuery docs中看到了submit(),我不应该在输入字段中使用名称“submit”。我试着改变它,没有运气。
1 个解决方案
#1
0
Well I'm not sure why but simply doing this worked:
嗯,我不确定为什么,但只是这样做:
$("#search_form").submit(function() {
var spinner_div = document.getElementById('spinner');
var spinner = new Spinner(opts);
spinner.spin(spinner_div);
});
#1
0
Well I'm not sure why but simply doing this worked:
嗯,我不确定为什么,但只是这样做:
$("#search_form").submit(function() {
var spinner_div = document.getElementById('spinner');
var spinner = new Spinner(opts);
spinner.spin(spinner_div);
});