New to Sublime Can't figure out snippets with javascript in them

白昼怎懂夜的黑 提交于 2019-12-13 18:45:13

问题


I have just started using sublimeText2 since eclipse is really slow with large projects through a VPN. I am trying to bring over some of my snippets. Most are working ok but the follow one is a ajax call that I use but won't work as a snippet. I am guess that there are characters that need to be escaped or something but I am not sure which ones

<snippet>
    <content><![CDATA[

    $.ajax({
        type: 'get',
        url: '.cfc',
        data: {method:''
            , var: var
            , var2:var
                },
        dataType: 'json',
        async: false,
        success: function(result){
            var result = jQuery.trim(result);
            console.log(result);
            } 
        }
    });     

]]></content>
    <tabTrigger>ajax</tabTrigger>
</snippet>

Can anyone see where I have gone wrong?


回答1:


Had to escape the $ with \$ and it works

<snippet>
    <content><![CDATA[

    \$.ajax({
        type: 'get',
        url: '.cfc',
        data: {method:''
            , var: var
            , var2:var
                },
        dataType: 'json',
        async: false,
        success: function(result){
            var result = jQuery.trim(result);
            console.log(result);
            } 
        }
    });     

]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>ajax</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>



回答2:


Maybe the CDATA tag enclosure causes this problem? Just a guess...



来源:https://stackoverflow.com/questions/13961566/new-to-sublime-cant-figure-out-snippets-with-javascript-in-them

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