1

IT IS SOLVED - WAITING TO MARK (stackoverflow delay)

There's no error in firebug. I've done this before I just can't figure out why it is not working. asyncFetchContent() is fired from elsewhere. contentController is created elsewhere.

function ContentController() {

}

ContentController.prototype.asyncFetchContent = function(){ 

         $.getJSON( '/content/TestContent.json', 
            function(data){
                contentController.displayContentCallback( data ); 
                } 
         );
}

ContentController.prototype.displayContentCallback = function( javascriptObject ){ 
    alert( "in callback");
    $( "#testID" ).html( javascriptObject.title );
}

Firebug will accept a breakpoint at the definition of displayContentCallback() and stop but then silently fails once you stepover. javascriptObject is undefined.

Thanks-in-advance,

Guido

2
  • Me thinks it will work if you just use longer names for those functions ? Commented Aug 16, 2012 at 23:15
  • Are you sure you should be prototyping. From the way you call the other functions, and the fact that your starting object is empty, maybe an object literal would serve your needs better. Commented Aug 16, 2012 at 23:53

2 Answers 2

2

From the manual:

Important: As of jQuery 1.4, if the JSON file contains a syntax error, the request will usually fail silently. Avoid frequent hand-editing of JSON data for this reason. JSON is a data-interchange format with syntax rules that are stricter than those of JavaScript's object literal notation. For example, all strings represented in JSON, whether they are properties or values, must be enclosed in double-quotes. For details on the JSON format, see http://json.org/.

Does your JSON contain an error?

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

1 Comment

Holy S**t. Thanks. I had a comment in the file which was the problem. Can I have the 3 hours spent working on this back please?
0

contentController.displayContentCallback( data ); does not exist. a) It's ContentController, not contentController and b) since you're using prototype, it has to be something like

function ContentController() {

}

ContentController.prototype.asyncFetchContent = function(){ 

     $.getJSON( '/content/TestContent.json', 
        function(data){
            var x = new ContentController();
            x.displayContentCallback( data ); 
        } 
     );
}

ContentController.prototype.displayContentCallback = function( javascriptObject ){ 
    alert( "in callback");
    $( "#testID" ).html( javascriptObject.title );
}

I'm pretty sure that should work.

2 Comments

Presumably, contentController is a variable in their code that contains an instance of ContentController. This is why it's bad to use names that only differ in case as it invites this confusion.
perhaps, but just in case... it would be nice if they could clear that up though

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.