3

I have an issue with my mobile application that I'm building using phonegap. I will be connecting this app to Magento and fetch products' details and display in the app. Oauth is configured for this url i.e. http://localhost/Basava/api/rest/products it gives me the json output if I type this url in address bar.

Now I've written an ajax query in my app to request the same url to fetch json that I'll use to display images in the app.

     <script type="text/javascript">
    function imageLoad() { 
        $.ajax({ 
        type: 'GET', 
        url: 'http://localhost/Basava/api/rest/products', 
        data: { get_param: 'value' }, 
        dataType: 'json',
        success: function (data) { 
        alert('success');
        ....
        ..
        }, 
        error: function() {
        alert('error');
        }
        });
        }
   <script>
   </head> <body onload="imageupload()">
   <div id="afui">
    ...`

I've removed the logic in the success function and <body> since that is not part of my problem. Since I'm developing it in phonegap environment, I tested it using intel xdk.
case 1: While using the debug tab in intel xdk I get the error alert.
case 2: Using the app emulator in intel xdk I get success alert.
case 3: Opening the app in my browser gives the error alert.

Now I cannot understand these. Can anyone please explain this? What I'm doing wrong? I want to be able to load the app page in browser for debug purposes.

Edit: Even if I change the error handler to look like this
alert: function(jqXHR, textStatus) { alert(textStatus); }

I just get an alert box, which displays nothing but plain error written on it.

elembivos
  • 399
  • 2
  • 14

1 Answers1

2

I believe that this issue because of invalid datatype, your server must return json in your case, you can try to remove it just for testing, if it works then you need ti check your backend code.

Also make sure that you running the browser without security mode because of cross domain policy:

For Ubuntu as example:

google-chrome--disable-web-security
Hazem Hagrass
  • 9,329
  • 10
  • 32
  • 54
  • Removing datatype did not help. I'm accessing the opencart API, which returns json which I'm sure about and checked. – elembivos Feb 16 '15 at 04:07