0

I have the following data on http://www.abcd.com/friends.json (this is not a real link but I am using one that is real on my project and I can connect to the server):

{John, Kyle, Abby, Greer, Rob, Cathy}

and I have the following script to autocomplete a text field:

$(function() {
    $("input#autocomplete").autocomplete({
    source: $.getJSON("http://www.abcd.com/friends.json")
});
  });

or

$(function() {
  var friendList = null;
  $.getJSON("http://www.abcd.com/friends.json", function(data){
     friendList = data;
     $("#friend" ).autocomplete({
    source: friendList
    });
  });
});

what am I doing wrong? both codes work if the json object is not called from a remote server Thanks for helping.

0

2 Answers 2

2

Your JSON is invalid. Probably you want to have something like this:

[ 'John', 'Kyle', 'Abby', 'Greer','Rob', 'Cathy' ]

Another possible error (as mentioned by JiDai in the comments) could be that you're getting the JSON from another server than your page is served. In that case either move your JSON to the same server or implement some CORS schema.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Sirko, Correction made no changes in result.
I have the server address correctly. There is only one server and not sure how the JSON can come from another server.
@Aamare is your code returning any errors or is there simply no autocomplete appearing?
0

Could you please replace "source" with "serviceUrl"

$(function() {
    $("input#autocomplete").autocomplete({
    serviceUrl: "http://www.abcd.com/friends.json"
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.