简体   繁体   English

有没有一种类似于Ajax的javascript技术来发送带有自定义方案网址的请求?

[英]Is there an Ajax-like javascript technique to send requests with custom scheme urls?

Is there any javascript framework/technique that allows to send asynchronous requests with custom scheme urls? 是否有任何JavaScript框架/技术可使用自定义方案网址发送异步请求? Trying this with Ajax: 尝试使用Ajax:

$.ajax({url: "myapp://root", success: function(result){
     console.log(result);
}});

expectedly gets me the below error 预计会给我以下错误

XMLHttpRequest cannot load myapp://root. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

I'm trying to figure a way to check whether a deep link sent to my iOS app has been successfully received before I redirect to its iTunes page. 我试图找到一种方法,以检查在重定向到其iTunes页面之前是否已成功接收到发送到我的iOS应用的深层链接。 My current javascript waits for a timeout before redirecting to iTunes, and that's not working as intended; 我当前的javascript等待超时,然后重定向到iTunes,这无法正常工作; a dialog pops up to ask whether the user wants to open the app, and if the timeout expires before they make their decision, they still get redirected to iTunes even if the dialog hasn't been answered/dismissed yet. 会弹出一个对话框,询问用户是否要打开该应用程序,并且如果超时在他们做出决定之前到期,即使尚未回答/关闭该对话框,他们仍将重定向到iTunes。

Here's my javascript: 这是我的JavaScript:

window.location = "myapp://somepath";
setTimeout(function() {
    window.location = "https://itunesurl";
}, 500);

Obviously increasing the timeout is not the solution I'm looking for. 显然,增加超时不是我想要的解决方案。

您可以尝试通过jsonp使用AJAX请求。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM