3 Replies Latest reply on May 6, 2013 9:53 AM by David Welling

    Render :string => someJSON .... works in Chrome but not in RhoSimulator

    David Welling

      I have been trying to get a BackBone app working in RhoMobile, so I need the controller to return some JSON to the Backbone.Sync method.

      The app is a little complex so I made a toy project to demonstrate the problem I am having.

      I generate a Rho application and change nothing except that I hardcode the port and add the following code to the app/index.erb:

       

      <script>

            $( document ).ajaxError(function(event, jqxhr, settings, exception) {

              console.log(exception);

            });

            var jqxhr = $.get("http://localhost:17778/app/TestStuff/getSomeRecords", function() {

              console.log("success");

            })

            .done(function() { console.log("second success"); })

            .fail(function() { console.log("error"); })

            .always(function() { console.log("finished"); });

      </script>

       

      and this code to the  controller:


      require 'rho/rhocontroller'

      require 'helpers/browser_helper'

      require 'JSON'

       

       

      class TestStuffController < Rho::RhoController

        include BrowserHelper

        def getSomeRecords

          @teststuff = TestStuff.find(:all)

             

              result = ::JSON.generate(@teststuff)

              @response['headers']['Content-Type']='application/json'

              render :string => result, :use_layout_on_ajax => false

        end

       

      This works just fine if I call http://localhost:17778/app/Index.erb or http://localhost:17778/app/TestStuff/getSomeRecords in Chrome, but the $.get call fails in the RhoSimulator (tried Android 4.0.3 and iPhone) with no information at all.  It fires the error handlers, but all the returned parameter properties are blank/nil/etc.  I've also tried to use a $.post with no better luck.

       

      I turned logging to MinSeverity = 0 and turned on net_trace, but I get nothing useful in the log:

      I 05/04/2013 19:19:31:016 00000dfc           HttpServer| Process URI: '/app/TestStuff/getSomeRecords'

      I 05/04/2013 19:19:31:016 00000dfc                  APP| RHO serve: /app/TestStuff/getSomeRecords

      I 05/04/2013 19:19:31:016 00000dfc              RhoRuby| require_compiled: TestStuff/test_stuff_controller

      I 05/04/2013 19:19:31:017 00000dfc              RhoRuby| require_compiled: helpers/browser_helper

      I 05/04/2013 19:19:31:018 00000dfc              RhoRuby| require_compiled: JSON

      I 05/04/2013 19:19:31:018 00000dfc              RhoRuby| require_compiled: json/common

      I 05/04/2013 19:19:31:021 00000dfc              RhoRuby| require_compiled: json/version

      I 05/04/2013 19:19:31:022 00000dfc              RhoRuby| require_compiled: json/pure

      I 05/04/2013 19:19:31:023 00000dfc              RhoRuby| require_compiled: json/pure/generator

      I 05/04/2013 19:19:31:027 00000dfc                  APP| const_missing: TestStuff

      I 05/04/2013 19:19:31:027 00000dfc                  APP| load_model: TestStuff

      I 05/04/2013 19:19:31:027 00000dfc              RhoRuby| require_compiled: TestStuff/test_stuff

      I 05/04/2013 19:19:31:027 00000dfc                  APP| model name: TestStuff

      I 05/04/2013 19:19:31:027 00000dfc                  APP| model class found

      I 05/04/2013 19:19:31:027 00000dfc                  APP| TestStuff : {"property"=>{}}

      I 05/04/2013 19:19:31:027 00000dfc                   DB| Open DB: C:/Code/RhoWorkspace/RhoMobileApplication1/rhosimulator/db/syncdblocal.sqlite

      I 05/04/2013 19:19:31:028 00000dfc                  APP| init_db_sources

      I 05/04/2013 19:19:31:028 00000dfc                  APP| start_id: 40004

      I 05/04/2013 19:19:31:028 00000dfc                  APP| Migrate schema sources: {}

      I 05/04/2013 19:19:31:029 00000dfc           HttpServer| GC Start.

      I 05/04/2013 19:19:31:030 00000dfc           HttpServer| GC End.

      I 05/04/2013 19:19:31:032 0000303c         QtMainWindow| Page load complete.

       


      What do I need to do to get this to work in the RhoSimulator?