4334738290
4334738290

Reputation: 393

Sublime snippet for ajax not working

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?

Upvotes: 1

Views: 287

Answers (1)

idleberg
idleberg

Reputation: 12882

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.

Upvotes: 3

Related Questions