简体   繁体   English

如何通过移动版本向网站的桌面版本发出 AJAX 请求

[英]How to make a AJAX request to a Desktop version of a site via the Mobile version

The mobile site I'm working on is completely different than its desktop version.我正在开发的移动站点与其桌面版本完全不同。 I need to make an AJAX call via the mobile site that will bring in data from the desktop version.我需要通过移动站点进行 AJAX 调用,该调用将从桌面版本中引入数据。 It seems that the AJAX call will make the GET request only on the calling version of the site.似乎 AJAX 调用只会在站点的调用版本上发出 GET 请求。

This code only returns the mobile site data when called on the mobile site:此代码仅在移动站点上调用时返回移动站点数据:

            $.ajax({
                type: "GET",
                url: window.location.href,
                success: function(data) {
                    var response = $(data);
                    //Returns mobile site data
                }
            });

Is there any way to force the GET request to use the desktop version?有没有办法强制GET请求使用桌面版本?

You're making an AJAX request to the current URL :您正在向当前 URL发出 AJAX 请求:

url: window.location.href

This is highly unconventional.这是非常非常规的。 But more to the point, the browser doesn't know or care what the difference is between "desktop" and "mobile".但更重要的是,浏览器不知道或不关心“桌面”和“移动”之间的区别。 It just makes requests and displays the responses.它只是发出请求并显示响应。 If the current URL doesn't handle the AJAX request then you'll need to make the request to a URL that does:如果当前 URL 不处理 AJAX 请求,则您需要向执行以下操作的 URL 发出请求:

url: 'someSpecificUrl'

To make this easier and consistent through the different versions of your application, I recommend separating your UI URLs from your API URLs.为了通过不同版本的应用程序使这更容易和一致,我建议UI URL 与 API URL分开 Both versions of the UI can then make requests to the same API URLs.然后,两个版本的 UI 都可以向相同的 API URL 发出请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在中预览移动网站 <iframe> 在引导模式下站点的桌面版本中 - How to preview mobile site in <iframe> in desktop version of site in bootstrap modal 如何在移动网站上创建“桌面版本”链接而不将其重定向到移动网站 - How to create a “Desktop Version” link on mobile website without it redirecting to the mobile site 如何在移动网站上创建“查看桌面版本”链接,而在解析后又不会循环回到移动版本? - How can I create a “view to desktop version” link on mobile site without it looping back to mobile version when it resolves? 如何仅在移动设备上显示桌面版本 - Blogger - How to only show desktop version on mobile - Blogger 如何使网站移动友好,一个选项是使每个网站的移动版本 - How to make the site mobile friendly ,one option is to make mobile version of each 通过滑动CSS(网站的移动版本)滑动菜单 - CSS (Mobile version of site) Sliding Menu via swipe 将移动用户重定向到桌面版本 - Redirecting a mobile user to a desktop version 如何在本地(通过扩展程序)请求网站的移动版本? - How can I request mobile version of a site locally (from my extension)? 如何使我的导航栏在 web 网站的移动版本上不可见? - How to make my navigation-bar invisible on mobile version of web site? 如何检测 iOS Mobile Safari 和 Chrome 的“请求桌面站点”模式? - How to detect “request desktop site” mode of iOS Mobile Safari and Chrome?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM