开发者

Test for AJAX in mobile browsers

开发者 https://www.devze.com 2022-12-10 13:13 出处:网络
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 su

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 enabli开发者_StackOverflow中文版ng 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消