Firefox和Malsup提交表单未定义错误

时间:2016-02-24 20:39:46

标签: javascript jquery ajax

这适用于Chrome和IE,但不适用于Firefox,我无法弄清楚原因。在此先感谢,这让我花了很长时间才弄明白。

这是我的代码:

<script type="text/javascript">
    $(document).ready(function() { //SEARCH FORM 
         $('#wrapper').delegate('#device_search','keyup', function(e) { 
            var searchquery = $('#device_search').val();
            localStorage.setItem("searchquery", searchquery);               
            if (searchquery) {
                $(".server_list_div").hide();     
                $(".search_results_div").show();       

                var options = { 
                    target:        '',
                    dataType:      'html',          
                    beforeSubmit:  showRequest_searchform,      
                    success:       showResponse_searchform
                }; 

                $("#search_form").ajaxSubmit(options); 


                function showRequest_searchform(formData, jqForm, options){         
                    return true; 
                }
                function showResponse_searchform(responseText, statusText, xhr, $form){                     
                    $(".search_results_div").html(responseText);
                } 
                return false;
            } else {
                $(".scroll_div").show(); 
                $(".scroll_div_results").hide(); 
            }
         });
    });
</script>   

这是我得到的错误:

enter image description here

2 个答案:

答案 0 :(得分:1)

你在FF中遇到了一个旧的bugif块中的函数不是hoisted

答案 1 :(得分:0)

尝试将您的功能移出if声明:

$(document).ready(function() {

function showRequest_searchform(formData, jqForm, options){         
                    return true; 
                }
                function showResponse_searchform(responseText, statusText, xhr, $form){                     
                    $(".search_results_div").html(responseText);
                } 
                return false;
                 //SEARCH FORM 
         $('#wrapper').delegate('#device_search','keyup', function(e) { 
            var searchquery = $('#device_search').val();
            localStorage.setItem("searchquery", searchquery);               
            if (searchquery) {
                $(".server_list_div").hide();     
                $(".search_results_div").show();       

                var options = { 
                    target:        '',
                    dataType:      'html',          
                    beforeSubmit:  showRequest_searchform,      
                    success:       showResponse_searchform
                }; 

                $("#search_form").ajaxSubmit(options); 



            } else {
                $(".scroll_div").show(); 
                $(".scroll_div_results").hide(); 
            }
         });
    });