smj2393 smj2393 - 6 months ago 21
Javascript Question

$.getJSON isn't working

I have been stuck on this all day, the getJSON just isn't working, I have tried loads of examples, but it still isn't working... Any help would be great. Thanks!

$.getJSON("", function(result)
$.each(result, function(i, person)

It only outputs the first console log "hi".

Here is the code from the new.JSON file:

$(document).ready(function () {
var data = $.parseJSON( "[{\"value\":\"32\",\"name\":\"R M\"},{\"value\":\"17\",\"name\":\"\"},{\"value\":\"15\",\"name\":\"Henry Hoggard\"},{\"value\":\"26\",\"name\":\"\"}]" ),
autocompleteInput = $("#contact_autocomplete");

autocompleteInput.autoSuggest(data, {
selectedItemProp: "name",
searchObjProps: "name",
asHtmlID: "contact_ids",
retrieveLimit: 10,
minChars: 1,
keyDelay: 0,
startText: '',
emptyText: 'No Results Found',
preFill: [{name : "",
value : ""}]

I want to access the
var data = $.parseJSON etc
section (contains the names and IDs)


Opening gives me response 401 unauthorized.

That is after confirming I want to install the certificate. There is a json response saying that I need to log in but the 401 response status header causes the request to fail.

Another thing is that you can't send xhr requests from site A to site B or from to or from to unless the site ( sends a cors header.

I'm using forcecors plugin for firefox so can make requests to other sites using that.

More about cross site scripting and same origin policy can be found on wikipedia, it explains how JSONP (is not the same as JSON) can be used and CORS.

After logging in with the test account you provided and running the code in the console I see what you mean, no error but the callback is never called. Opening I can see that the url does not return JSON, the response is:

    $(document).ready(function () {
      var data = $.parseJSON( "[]" )

This is not JSON so the callback is never called since converting the response to a javascript object fails silently.