$.ajax not function(已 解决:jQuery库冲突解决办法)

js文件开头已的定义$符号.导致后续,$.ajax 错误,不能识别$符号.,

参考:https://www.cnblogs.com/buwan/p/5346096.html 

http://www.lovetime.top/2018/01/21/jQuery-clash-1/ 

得到灵感

文件开头自定的处:

const $ = (el) => document.querySelector(el);
$('.selectIpt').addEventListener('change', handleFiles);

function handleFiles() {
    const files = this.files;
    for (let i = 0, len = files.length; i < len; i++) {
        showFilePreview(files[i]);
    }
    //上传文件
    uploadfile();
}

修改前的:

<script>
    var btn = document.getElementById("processTask");
    btn.addEventListener('click',function(){
        var method = GetUrlPara();
        // console.log(method);
        // console.log(filename);
        $.ajax({
            type: 'POST',
            url: "/getfilename",
            data: {"filename":filename,"method":method},
            cache: false,
            processData: false,
            contentType: false,
            success: function (ret) {
                alert(ret);
            }
        });
    },false)
</script>

修改后的:

//提交文件名称,执行操作方法
function commitfilename() {
    jQuery.noConflict();
    var method = GetUrlPara();
    jQuery(document).ready(function(){
        jQuery("#processTask").text("文件上传中....!")
        jQuery.ajax({
            type: 'POST',
            url: "/ingetfilename",
            data: {"filename":filename,"method":method},
            dataType:"json",
            success: function (ret) {
                alert(ret);
            }
        });

    })
}

 

posted @ 2019-10-21 15:46  码农编程进阶笔记  阅读(95)  评论(0编辑  收藏  举报
返回顶部 有事您Q我