2 Replies Latest reply on Feb 19, 2013 8:16 AM by Bhuvana V

    Ajax call not working.. pl help.

      Hi ,

       

      I am struggling with the ajax inssue for quite few days.. Pl help.

      i connected the device and copied the apps and config directory.

       

      Here is the description of my apps.json file.

      {

      "name": "My Demo",

      "url": "http://127.0.0.1:83/UserDrive/apps/demo/index.html",

      "icon": "http://127.0.0.1:83/UserDrive/apps/demo/price_check_icon.png"

      }

       

      The index file contains username and password and a login button.

       

      We have a webservice which takes username and password as argument in json object and send the response in json format.

      I am susing the ajax call on the login button click from the  index.html page (which is residing in my device).

      Everytime i am getting the response as "'Not connect.\n Verify Network". (response code === 0)

      The same url if i give in the browser works fine.

      the device is having wifi connection also.

       

      Here is the code:

       

      var req = $.ajax({

                          type: 'post',

                          url: finalURL,

                          cache: false,

                          dataType: 'json',

                          success: function(d) {

                              alert('success');

                          },

                          error: function(jqXHR, exception) {

                              if (jqXHR.status === 0) {

                                  alert('Not connect.\n Verify Network.');

                              } else if (jqXHR.status === 404) {

                                  alert('Requested page not found. [404]');

                              } else if (jqXHR.status === 500) {

                                  alert('Internal Server Error [500].');

                              } else if (exception === 'parsererror') {

                                  alert('Requested JSON parse failed.');

                              } else if (exception === 'timeout') {

                                  alert('Time out error.');

                              } else if (exception === 'abort') {

                                  alert('Ajax request aborted.');

                              } else {

                                  alert('Uncaught Error.\n' + jqXHR.responseText);

                              }

                          },

                          async: true

                      });

       

      Please help.. what is the issue with this code..

       

      Thank you,

      Bhuvana.

        • Re: Ajax call not working.. pl help.
          Robert Galvin

          Are you sure you want to do a POST instead of a GET? I do not see any data being passed for post. You did not provide what you are using for 'finalURL' as well. Also if the device is having Wifi issues then that may be the source of the problem. You may not have RevA hardware - I would check with whoever you got it from.

            • Re: Ajax call not working.. pl help.

              Dear Robert,

               

              Well.. i found the issue.

              The problem is with json.

              Since i am sending the request from other domain which doesnt have the access/permission/authorization the device is always responding with 0.

              But when i changed it to jsonp and also changed my call back fucntions handling it started wokring...

               

              Thank you,

              Bhuvana.