Home >Web Front-end >JS Tutorial >Solution to the conflict between jquery and NVelocity_jquery
There are several solutions when NVelocity's $ conflicts with Jquery's $:
1.
Use jQuery.noConflict. For example: var j = jQuery.noConflict(); j.ajax();
Disadvantage: When using jQuery related plug-ins, the plug-ins will become invalid!
2.
Use jQuery instead of $. Such as: jQuery.ajax();
Disadvantages: Not suitable for expansion. Once replaced with a third-party library, it will be troublesome
3.
wrap conflicting methods in jQuery.
If $.ajax() conflicts in Velocity, redefine it as follows:
function dw(){}
dw.ajax=function(s){ jQuery.ajax(s); } dw .ajax();
4.
Define a $JQ as $. You can use ${JQ}AJAX in js in the future.
Write (definition) like this at the front desk: #set($JQ="$.")
I recommend the fourth method.