1 Reply Latest reply on Nov 13, 2012 1:51 AM by Dave Philips

    Blackberry 7.1 Simulator and JQuery AJAX call

    Dave Philips

      I'm trying to perform a simple ajax call in the Blackberry 7.1 simulator (9860) using JQuery


      The erb file is as follows:


      <div data-role="page">
        <div data-role="header" data-position="inline">
          <h1>New <%= @model001.title %></h1>
          <a href="<%= url_for :action => :index %>" class="ui-btn-left" data-icon="back" data-direction="reverse">
          <script type="text/javascript">
           function SubmitForm() {
              var url =   $("form", $.mobile.activePage).attr("action");
              var data = $("form", $.mobile.activePage).serialize();
                  type: 'POST',
                  url:  url,
                  success: function(data) { alert('data: ' + data); }
        <div data-role="content">
          <form method="POST" action="<%= url_for :action => :create %>">
            <input type="hidden" name="id" value="<%= @model001.object %>"/>
                <div data-role="fieldcontain">
                  <label for="field1" class="fieldLabel">Field1</label>
                  <input type="text" id="field1" name="field1" value="<%= @model001.field1 %>" />
                <div data-role="fieldcontain">
                  <label for="field2" class="fieldLabel">Field2</label>
                  <input type="text" id="field2" name="field2" value="<%= @model001.field2 %>" />
                <div data-role="fieldcontain">
                  <label for="field3" class="fieldLabel">Field3</label>
                  <input type="text" id="field3" name="field3" value="<%= @model001.field3 %>" />
            <a data-role="button" href="#" onclick="SubmitForm(); return false;">Create</a>


      And below is the ruby action that is called:


      def create
          render :string => @params.inspect, :use_layout_on_ajax => true


      As you'll see, all I'm doing is sending the params back to the client.


      The problem is that the @params object is always empty.


      If I run it in the RhoSimulator it all works as expected, and I get the alert in the success function displaying the returned data.


      If I try and run it in the 9860 simulator, the param object returned to the success function is blank.


      I've tried setting use_bb_full_browser = 1 inside the rhoconfig, but this doesn't have any effect.


      I've also tried adding the following to the jquery ajax call:


      beforeSend: function(xhr) { xhr.setRequestHeader("HTTP_ORIGIN", "http://localhost"); }


      But again this doesn't work.


      I read somewhere that blackberry don't support AJAX POST, but it is exactly the same when using GET.


      Any help would be greatly appreciated.