开发者

I have a missing semicolon per JSLint

开发者 https://www.devze.com 2023-04-02 23:36 出处:网络
My JS code: $(\"#1\").autocomplete( { source: function (request, response) { \"use strict\"; $.ajax( { url: \"http://www.domain.com/foo/\",

My JS code:

$("#1").autocomplete(
{
    source: function (request, response)
    {
        "use strict";
        $.ajax(
        {
            url: "http://www.domain.com/foo/",
            dataType: "jsonp",
            data: {
                api_key: "123",
                search_term: request.term
            },
            success: function (data)
            {
                response($.map(data.data, function (item)
                {
                    return {
                        label: item.username,
                        value: item.user_id
                    }
                }));
            }
        });
    },
    minLength: 2
});

JSLint gives me the following error:

Error:
Problem at line 21 character 9: Expected ';' and instead saw '}'.

}

I don't see where this semicolon shoul开发者_如何学Pythond go. What am I not seeing? The code works when I tested it.


It wants it here;

                return {
                    label: item.username,
                    value: item.user_id
                }; <--


 return {
                            label: item.username,
                            value: item.user_id
                        };


return {
    label: item.username,
    value: item.user_id
}

should read

return {
    label: item.username,
    value: item.user_id
};


Your ; needs to go after the return{} block. Consider using something like Notepad++ to pinpoint line numbers.

0

精彩评论

暂无评论...
验证码 换一张
取 消