jQuery autocomplete works with a local string but not when the same String is called off the server

Posted by Ankur on Stack Overflow See other posts from Stack Overflow or by Ankur
Published on 2010-05-10T14:50:21Z Indexed on 2010/05/10 14:54 UTC
Read the original article Hit count: 262

Filed under:
|
|

This is related to the question I asked at http://stackoverflow.com/questions/2802948/how-to-make-an-ajax-call-immediately-on-document-loading

My code is:

$(document).ready(function(){
    $.ajax({
        type: "GET",
        url: "../AutoComplete",
        success: function(data) {
            var dataArray = data;
            alert(dataArray);
            $("#example").autocomplete(dataArray);
        }
    });
});

The value that is printed in the alert is:

"Manuscript|Text|Information Object|Basketball|Ball|Sporting Equipment|Tarantula|Spider|Australian Spider|Cricket Player|Medieval Artefact|Person|Sportsperson|Leonardo Da Vinci|Country|Language|Inventor|Priest|Electronics Manufacturer|Object|letter|Artefact|governance model|Organism|Animal".split("|");

If instead I do this:

$(document).ready(function(){
        $.ajax({
            type: "GET",
            url: "../AutoComplete",
            success: function(data) {
                var dataArray = "Manuscript|Text|Information Object|Basketball|Ball|Sporting Equipment|Tarantula|Spider|Australian Spider|Cricket Player|Medieval Artefact|Person|Sportsperson|Leonardo Da Vinci|Country|Language|Inventor|Priest|Electronics Manufacturer|Object|letter|Artefact|governance model|Organism|Animal".split("|");                  
                alert(dataArray);
                $("#example").autocomplete(dataArray);
            }
        });
    });

It works fine?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about autocomplete