Sublime snippet for ajax not working

僤鯓⒐⒋嵵緔 提交于 2019-12-02 09:03:10

问题


I am trying to create a snipped that every time I type ajax follow by the tab button to insert code, but when I type ajax and press the tab button it just deletes the ajax text for the snippet, I have saved it as ajax.sublime-snippet

My snippet

<snippet>
    <content><![CDATA[
    $('#${1:binder}').on("", function()
    {
        $.ajax({
            url: ${2:url},
            type: ${3:post},
            success: function(data)
            {
                if(!data.success)
                {
                    $('#error_message').html(data.error + alert_close).show();
                }else{
                    $('#success_message').html(data.success + alert_close).show();

                }
            }
        });
    });
]]></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>

How can I fix this?


回答1:


Escape those dollar-signs that are part of the code, not of the snippet

<snippet>
    <content><![CDATA[
    \$('#${1:binder}').on("", function()
    {
        \$.ajax({
            url: ${2:url},
            type: ${3:post},
            success: function(data)
            {
                if(!data.success)
                {
                    \$('#error_message').html(data.error + alert_close).show();
                }else{
                    \$('#success_message').html(data.success + alert_close).show();    

                }
            }
        });
    });
]]></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>

You also might want to uncomment the scope and set it to source.js.



来源:https://stackoverflow.com/questions/36465017/sublime-snippet-for-ajax-not-working

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