Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery代码冲突_Jquery_Conflict - Fatal编程技术网

jQuery代码冲突

jQuery代码冲突,jquery,conflict,Jquery,Conflict,为通用标题道歉 我有两个jQuery文件,一个处理表单提交,另一个处理页面超链接 表单提交检查表单条目是否为空,如果为空,则会通知用户,并在填写表单时显示错误消息。表单数据传递到处理文件 超链接将新页面数据加载到div中,这些新页面数据通常包括处理文件处理的表单 我不知道为什么-但是大约60%的时间表单提交会在点击后“刷新”,并加载主索引页面或上次访问的页面。这似乎完全是随机的 我不明白为什么会发生这种情况,如果有人能告诉我,我将不胜感激 表格提交代码: $(document).ready(fu

为通用标题道歉

我有两个jQuery文件,一个处理表单提交,另一个处理页面超链接

表单提交检查表单条目是否为空,如果为空,则会通知用户,并在填写表单时显示错误消息。表单数据传递到处理文件

超链接将新页面数据加载到div中,这些新页面数据通常包括处理文件处理的表单

我不知道为什么-但是大约60%的时间表单提交会在点击后“刷新”,并加载主索引页面或上次访问的页面。这似乎完全是随机的

我不明白为什么会发生这种情况,如果有人能告诉我,我将不胜感激

表格提交代码:

$(document).ready(function(){

    $('.ajax_form').submit(function() {

        // check for empty inputs
        var errors = 0;
        $(".ajax_form :input").map(function(){
            if(!$(this).val()) {
                errors++;
            }  
        });

        // if empty inputs inform user
        if(errors > 0){
            $('#results').text("All fields are required");
            return false;
        }

        // hide form and show loader
        $(".ajax_form").slideUp("normal");
        $('#results').html('<span id="load">Loading..</span>');

        // post data to processing file
        $.post(
            'processing.php',
            $(this).serialize(),
            function(data){
                $("#results").slideDown("normal");
                $("#results").html(data)
            }
        );

        return false;

    });

});
$(文档).ready(函数(){
$('.ajax_form')。提交(函数(){
//检查是否有空输入
var误差=0;
$(“.ajax\u表单:输入”).map(函数(){
if(!$(this.val()){
错误++;
}  
});
//如果输入为空,则通知用户
如果(错误>0){
$(“#结果”).text(“所有字段均为必填项”);
返回false;
}
//隐藏表单并显示加载程序
$(“.ajax_form”).slideUp(“正常”);
$('#results').html('加载..');
//将数据发布到处理文件
美元邮政(
'processing.php',
$(this).serialize(),
功能(数据){
$(“#结果”)。向下滑动(“正常”);
$(“#结果”).html(数据)
}
);
返回false;
});
});
导航代码:

$(document).ready(function(){

    // if hash is already set, load linked data
    var hash = window.location.hash.substr(1);
    $('#nav li a').each(function(){
        if(hash == $(this).attr('href')){
            var toLoad = hash + '.php';
            $('#content').load(toLoad)
        }
    });

    // each menu item on click load linked data
    $('#nav li a').click(function(){

        var toLoad = $(this).attr('href') + '.php';
        window.location.hash = $(this).attr('href');

        $('#content').prepend('<span id="load">Loading..</span>');
        $('#content').hide();
        $('#content').load(toLoad);
        $('#content').slideDown('normal');

        return false;

    });

});
$(文档).ready(函数(){
//如果已设置哈希,请加载链接数据
var hash=window.location.hash.substr(1);
$('#nav li a')。每个(函数(){
if(hash==$(this.attr('href')){
var toLoad=hash+'.php';
$(“#内容”).load(toLoad)
}
});
//单击“加载链接数据”时的每个菜单项
$('#nav li a')。单击(函数(){
var toLoad=$(this.attr('href')+'.php';
window.location.hash=$(this.attr('href');
$(“#content”).prepend('Loading..);
$(“#内容”).hide();
$(“#内容”).load(toLoad);
$(“#内容”)。向下滑动(“正常”);
返回false;
});
});

您的表单刷新,因为在到达
部分之前返回false脚本中断
以前的某个地方

使用
firebug
或类似方法检测此问题。确保处理所有结果或每种情况


可能是快速试运行可以检测到间隙。

我的粗略猜测是,由于某种原因,单击功能失败,不会返回false,导致链接像正常一样打开。JavaScript控制台中是否有错误?也许您应该检查
如果(!$(this).val().length){errors++;}
?另外,您的
返回false在代码的下面。您应该使用
$('.ajax_form').submit(函数(e){e.preventDefault();…})您是从cdn加载jquery吗?我没有收到任何错误。不,表单看起来确实“正常”提交。如下所述,我尝试了preventDefault();-同样的问题。