[英]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.