NS_ERROR_NOT_AVAILABLE: Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMWindow.alert]

1

I am calling an javascript variable inside autocomplete function and and making url in ajax from textbox value but it is showing undefined.

function fetchRecords()
{
    var searchStr=$("#tags").val();

    var finalLink=urlformjavascriptvariable;
    $.ajax({
    url:finalLink,

    type: 'GET',
    dataType :'jsonp',
    async: false,
    crossDomain:true,
    success: function(data) {
    var resp = data.response;
    var availableTags = "[";
    for (i = 0; i <= 10; i++) {
        if(resp.messages.message[i].subject.$ != undefined)
            var postSub = resp.messages.message[i].subject.$;
    if (i < 10) {
        availableTags +="\"" +postSub + "\",";
    }
    else {
        availableTags +="\""+ postSub+"\"";
    }
}
availableTags += "]";
availableTags=eval(availableTags);

        $("#tags").autocomplete({
            source: availableTags,

        });
    }
});
}
</script>

<div class="ui-widget">
<input id="tags" class="input_width mgtop20" autocomplete="on"  onKeyup="fetchRecords();" type="text" name="post_search" value="" placeholder="Search the Community for answers"  /></div>

It shows variables undefined

jquery
asked on Stack Overflow Nov 15, 2013 by Mayank Kapahi • edited Feb 23, 2015 by djds23

1 Answer

2
for (i = 0; i <= 10; i++) {

This is the offending line of code. The ajax call is going past the number of items in your list.

Switching the same statement to

for (i = 0; i < resp.messages.message.length; i++) {

will resolve the issue.

answered on Stack Overflow Dec 12, 2013 by Chris

User contributions licensed under CC BY-SA 3.0