views:

460

answers:

1

I'm building a mobile web application that may or may not rely on ajax, depending on whether the user's browser supports javascript. Since I'm using JQuery, I want to make sure the mobile browser supports AJAX through JQuery before enabling my AJAX functionality.

I'm running into a problem with Opera Mini because of the way it renders pages, and I'm not sure how to check it. Here's the code I'm using to test for AJAX:

$(document).ready(function () {
 $.get(
  'test.txt',
  function() {
   init_ajax();
  }
 );
});

Where init_ajax() enables my ajax functionality and disables my static functionality.

The problem is, Opera Mini runs this code successfully before outputting the page to the browser, but then ajax does not actually work on the rendered page. I tried running this function in a setTimeout instead of on document.ready, but encountered the same problem.

Is there a universal way to accurately test for the presence of AJAX in mobile browsers?

P.S. If you want to test your solution in Opera Mini, there's a fully functional emulator here:

http://www.opera.com/mini/demo/

[Edit] I should mention that this application needs to make an ajax call approximately once per minute using setInterval, so even though Opera Mini does support some ajax when it is triggered by an onclick, I don't believe there's any way to make it support ajax calls made at a certain interval. If we could test for this, that would likely solve the problem above.

A: 

Doesn't Opera Mini retrieve web requests on Operas' servers render the pages and then deliver the output (in the form of images and text) to the target with reduced functionality? With the rendering happening on the Opera Mini Server farm hence no real back and forth communication between the client and the Web server, you can't actually do ajax.

You probably need another method of performing the check for Opera Mini, looking at the user-agent for "Opera Mini/1.2" would be ideal. As for performing a check for mobile browsers, well, it depends upon the scope of the functionality provided by the mobile browser. Sometimes you just can't check and will have to pull out particular mobile browsers by name.

More info here Designing With Opera Mini in Mind.

skirmish
I think you're right. As far as I can tell, Opera Mini executes scripts for about 2 seconds, then stops and delivers the page. So for about 2 seconds the page is fully functional, meaning any test that happens in that period will render incorrect results.
Travis
The opera mini server executes the scripts and performs the request and then delivers it to the mobile client. So really in this case, the only option is to identify it directly by user agent and disable ajax functionality.
skirmish