Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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_Salesforce_Javascript_Visualforce - Fatal编程技术网

Jquery 未捕获类型错误:无法调用方法';无冲突';未定义的

Jquery 未捕获类型错误:无法调用方法';无冲突';未定义的,jquery,salesforce,javascript,visualforce,Jquery,Salesforce,Javascript,Visualforce,我试图在SalesForce中使用javascript和jquery创建一个小部件,但遇到了一个错误:未捕获类型错误:无法调用未定义的方法“noConflict” 下面是我正在使用的代码 (function() { // Localize jQuery variable var $j; /******** Load jQuery if not present *********/ if (window.jQuery === undefined || window.jQuery.fn.jque

我试图在SalesForce中使用javascript和jquery创建一个小部件,但遇到了一个错误:未捕获类型错误:无法调用未定义的方法“noConflict”

下面是我正在使用的代码

(function() {

// Localize jQuery variable
var $j;

/******** Load jQuery if not present *********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2') {
    var script_tag = document.createElement('script');
    script_tag.setAttribute("type","text/javascript");
    script_tag.setAttribute("src",
        "https://ap1.salesforce.com/resource/go/jquery.min.js");
    if (script_tag.readyState) {
      script_tag.onreadystatechange = function () { // For old versions of IE
          if (this.readyState == 'complete' || this.readyState == 'loaded') {
              scriptLoadHandler();
          }
      };
    } else {
      script_tag.onload = scriptLoadHandler;
    }
    // Try to find the head, otherwise default to the documentElement
    (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
} else {
    // The jQuery version on the window is the one we want to use
    $j = window.jQuery;
    main();
}

/******** Called once jQuery has loaded ******/
function scriptLoadHandler() {
    // Restore $ and window.jQuery to their previous values and store the
    // new jQuery in our local jQuery variable
    $j = window.jQuery.noConflict(true);
    // Call our main function
    main(); 
}

/******** Our main function ********/
function main() { 
    $j(document).ready(function($) { 
        /******* Load CSS *******/
       var css_link = $("<link>", { 
            rel: "stylesheet", 
            type: "text/css", 
            href: "style.css" 
        });
        css_link.appendTo('head');          

        /******* Load HTML *******/
        var jsonp_url = "http://al.smeuh.org/cgi-bin/webwidget_tutorial.py?callback=?";
        $.getJSON(jsonp_url, function(data) {
          $('#example-widget-container').html("This data comes from another server: " + data.html);
        });

    });
}

})(); // We call our anonymous function immediately
(函数(){
//本地化jQuery变量
var$j;
/********如果不存在jQuery,则加载它*********/
if(window.jQuery==undefined | | window.jQuery.fn.jQuery!=='1.4.2'){
var script_tag=document.createElement('script');
script_tag.setAttribute(“type”、“text/javascript”);
script_tag.setAttribute(“src”,
"https://ap1.salesforce.com/resource/go/jquery.min.js");
if(script_tag.readyState){
script_tag.onreadystatechange=function(){//用于旧版本的IE
如果(this.readyState=='complete'| | this.readyState=='loaded'){
scriptLoadHandler();
}
};
}否则{
script_tag.onload=scriptLoadHandler;
}
//尝试查找头部,否则默认为documentElement
(document.getElementsByTagName(“head”)[0]| | document.documentElement).appendChild(script_标记);
}否则{
//窗口上的jQuery版本就是我们想要使用的版本
$j=window.jQuery;
main();
}
/********加载jQuery后调用******/
函数scriptLoadHandler(){
//将$和window.jQuery恢复为其以前的值并存储
//本地jQuery变量中的新jQuery
$j=window.jQuery.noConflict(true);
//调用我们的主要函数
main();
}
/********我们的主要职能********/
函数main(){
$j(文档).ready(函数($){
/*******加载CSS*******/
var css_link=$(“”,{
rel:“样式表”,
键入:“文本/css”,
href:“style.css”
});
css_link.appendTo('head');
/*******加载HTML*******/
var jsonp_url=”http://al.smeuh.org/cgi-bin/webwidget_tutorial.py?callback=?";
$.getJSON(jsonp_url,函数(数据){
$('#示例小部件容器').html(“此数据来自另一台服务器:“+data.html”);
});
});
}
})(); // 我们立即调用匿名函数

在浏览器控制台中,错误指向scriptLoadHandler函数的第一行。

声明本地jquery变量,如下所示:

//Localize jQuery variable
var $j = jQuery.noConflict();

您的页面中没有包含jQuery是的,我是通过检查jQuery是否存在来动态包含它的,您可以在上面代码的第3行看到它。当我打开它时,它似乎不包含jQuery代码。您是否尝试过从其他地方包含jquery?我也尝试过这样做。