Reputation: 1957
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!
console.log("hi");
$.getJSON("https://pod.cscf.me/conversations/new.json", function(result)
{
console.log("workingggggg");
$.each(result, function(i, person)
{
console.log("itworks2");
});
});
It only outputs the first console log "hi".
Here is the code from the new.JSON file:
<script>
//<![CDATA[
$(document).ready(function () {
var data = $.parseJSON( "[{\"value\":\"32\",\"name\":\"R M\"},{\"value\":\"17\",\"name\":\"[email protected]\"},{\"value\":\"15\",\"name\":\"Henry Hoggard\"},{\"value\":\"26\",\"name\":\"[email protected]\"}]" ),
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 : ""}]
});
autocompleteInput.focus();
});
//]]>
</script>
I want to access the var data = $.parseJSON etc
section (contains the names and IDs)
Upvotes: 0
Views: 655
Reputation: 39250
Opening https://pod.cscf.me/conversations/new.json 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 sub.A.com to A.com or from A:80.com to A:102.com unless the site (pod.cscf.me) 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 https://pod.cscf.me/conversations/new.json I can see that the url does not return JSON, the response is:
<script>
//<![CDATA[
$(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.
Upvotes: 2