Results 1 to 3 of 3
  1.    #1  
    I am trying to display the results of an ajax call and I'm hoping that someone here can let me know just where I am going wrong.

    I believe that I am getting the results from the ajax call back correctly, I'm just not sure how to display the results.

    Also, I am not sure just how I need to define my model for my list widget that will display the results. Here's my code, any help would be much appreciated.

    Ok, so here is how I call the request and put the results in a variable:

    Code:
    new Ajax.Request(curlCourses, {
            method: 'get',
            asynchronous: true,
            onSuccess: this.gotSearchcourses.bind(this),
            onFailure: this.errSearchcourses.bind(this),
            onLoading: this.loadingCourses.bind(this)
        });
    
    
    ShowCourseAssistant.prototype.gotSearchcourses = function(transport){
        this.spinnerModel.spinning = false;
        this.controller.modelChanged(this.spinnerModel);
        this.foundCourses = transport.responseJSON;
        this.controller.stageController.pushScene("find-course", this.foundCourses);
    }
    At the end of getting the results I am calling my find-course scene and passing the variable that contains the ajax results. So, I'm pretty sure that I am getting the results back from the call as the find-course scene is opening up, which means that the onSuccess: part of the ajax call is being triggered. Here is what I am doing in the find-courses scene:

    Code:
    function FindCourseAssistant(courselist) {
        this.coursesAll = courselist;
    }
    
    FindCourseAssistant.prototype.setup = function() {
        var CourselistAttrs = {
            listTemplate: 'find-course/listcontainer', 
            itemTemplate: 'find-course/listItem',
            emptyTemplate: 'find-course/empty',  
            swipeToDelete: false  
        };
        
        this.CourselistModel = {items: []};
        
        this.controller.setupWidget('course_list', CourselistAttrs, this.CourselistModel);
    
    }
    
    FindCourseAssistant.prototype.populateCourses = function(event){
        this.CourselistModel.items = $A(this.coursesAll.responseData.results);
        this.controller.modelChanged(this.CourselistModel, this);
        this.controller.get('info_area').update('First course: ' + this.coursesAll.course(0).name);
    }
    
    FindCourseAssistant.prototype.activate = function(event) {
        db = openDatabase("golfcaddie","1.0.0");
        populateCourses();
    
    }
    
    
    FindCourseAssistant.prototype.deactivate = function(event) {
        /* remove any event handlers you added in activate and do any other cleanup that should happen before
           this scene is popped or another scene is pushed on top */
    }
    
    FindCourseAssistant.prototype.cleanup = function(event) {
        /* this function should do any cleanup needed before the scene is destroyed as 
           a result of being popped off the scene stack */
    }
    The one area that I am not sure about is how to setup the model to display the results. In my code I am simply doing a this.CourselistModel = {items: []}; but I really have no idea if this is correct or not.

    Again, any help would be much appreciated on this.
  2. #2  
    I use copious amounts of Mojo.Log.error("My object %j", myObject) to find states of things. (Prints out the JSON represention of myObject, but can have issues with big objects.

    this.CourselistModel.items should be an empty Array. If that is what you are trying, then that looks fine.
  3.    #3  
    sacherjj, how would I view the info that I push to Mojo.Log.error ?

    this.CourselistModel.items is empty when I initialize the model, but later on I set the items to:

    this.CourselistModel.items = $A(this.coursesAll.responseData.results);

    just not sure if that is correct.

Posting Permissions