在移动浏览器中测试AJAX(Test for AJAX in mobile browsers)

编程入门 行业动态 更新时间:2024-10-27 11:19:38
在移动浏览器中测试AJAX(Test for AJAX in mobile browsers)

我正在构建一个可能依赖或不依赖于ajax的移动Web应用程序,具体取决于用户的浏览器是否支持javascript。 由于我使用的是JQuery,我想在启用AJAX功能之前确保移动浏览器通过JQuery支持AJAX。

我正在遇到Opera Mini的问题,因为它呈现页面的方式,我不知道如何检查它。 这是我用来测试AJAX的代码:

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

其中init_ajax()启用了我的ajax功能并禁用了我的静态功能。

问题是,Opera Mini在将页面输出到浏览器之前成功运行此代码,但是ajax实际上并不在渲染页面上工作。 我尝试在setTimeout而不是document.ready中运行此函数,但遇到了同样的问题。

有没有通用的方法来准确测试移动浏览器中AJAX的存在?

PS如果你想在Opera Mini中测试你的解决方案,那里有一个功能齐全的模拟器:

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

[编辑]我应该提一下,这个应用程序需要使用setInterval每分钟大约进行一次ajax调用,所以即使Opera Mini在onclick触发时支持某些ajax,我也不相信有任何方法可以实现它。支持以一定间隔进行的ajax调用。 如果我们可以测试这个,那可能会解决上面的问题。

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.

最满意答案

Opera Mini是否在Opera的服务器上检索Web请求以呈现页面,然后以减少的功能将输出(以图像和文本的形式)传递给目标? 由于Opera Mini Server服务器场上的渲染发生,因此客户端和Web服务器之间没有真正的来回通信,您实际上无法执行ajax。

您可能需要另一种方法来执行Opera Mini的检查,查看“Opera Mini / 1.2”的用户代理是理想的。 至于对移动浏览器执行检查,它取决于移动浏览器提供的功能的范围。 有时您无法检查并且必须按名称提取特定的移动浏览器。

更多信息在这里设计Opera Mini 。

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.

更多推荐

本文发布于:2023-07-22 19:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222716.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:器中   测试   AJAX   browsers   mobile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!