How to fix Prototype conflict with Highchart?

烂漫一生 提交于 2019-11-28 10:26:16

问题


I have an AJAX action and trying to use Highchart at the same time that's why I need Prototype to be included.

Here is my code but is not showing the Highchart graph:

<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7/prototype.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>

<div id="contain" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

Here is the information: http://jsfiddle.net/dhdSL/4/

Of course is working 100% without Prototype: http://jsfiddle.net/dhdSL/5/

I tried jQuery.noConflict(); and is not showing the Highchart graph http://jsfiddle.net/dhdSL/6/

And tried $.noConflict(); and is not showing the Highchart graph http://jsfiddle.net/dhdSL/7/

I was searching in Stack Overflow for an answer, blogs, Facebook, books, Google and spent six months and still don't find the answer.

I tried changing Prototype in all version but still not working and is not showing errors in console.

According with a friend told me to include noConflict at the end but is not showing in google chrome browser and is showing an error: http://jsfiddle.net/dhdSL/8/

When open the error I'm getting another error:


回答1:


Wrap your jQuery into an anonymous function to protect the variable from being interfered with by Prototype. http://jsfiddle.net/amyamy86/s6ms3/

(function($) {

    $.noConflict();
    $(function () {
        $('#contain').highcharts({
         ....
        });
     });

}(jQuery));


来源:https://stackoverflow.com/questions/23369849/how-to-fix-prototype-conflict-with-highchart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!