简体   繁体   English

Cordova 10 无法将 ajax 发布到 http Z572D4E421E5E6B9BC111D815E8Z07

[英]Cordova 10 unable to post ajax to http url

I'm trying to send json data to an http url without success (I tried to send same data to an other https with success). I'm trying to send json data to an http url without success (I tried to send same data to an other https with success). I have this settings: config.xml我有这个设置: config.xml

<access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />

AndroidManifest.xml AndroidManifest.xml

 android:usesCleartextTraffic="true"

html header html header

$.ajax({
                                    type: "GET",
                                    url: url,
                                    dataType: "jsonp",
                                    jsonp: 'callback',
                                    crossDomain: true,
                                    async: true,
                                    data: {id:results.rows.item(i).id, bolla:results.rows.item(i).bolla, anno:results.rows.item(i).anno, magazzino:results.rows.item(i). magazzino, articolo:results.rows.item(i).articolo, quantita:results.rows.item(i).quantita, term:terminale},
                                    success: function(data) {
                                        console.log(data)
                                    },
                                    error:function(xhr,textStatus,err)
                                    {
                                        alert("readyState: " + xhr.readyState);
                                        alert("responseText: "+ xhr.responseText);
                                        alert("status: " + xhr.status);
                                        alert("text status: " + textStatus);
                                        alert("error: " + err);
                                    }
                            });

If I use json it returns devicereadystate=0 and error if I use jsonp it returns devicereadystate=4 and error 404 (the url is correct if I paste to a browser it works)如果我使用 json 它返回 devicereadystate=0 和错误如果我使用 jsonp 它返回 devicereadystate=4 和错误 404(如果我粘贴到浏览器它工作 url 是正确的)

I believe this is because with cordova-android 10.0.x, the webview is now acting as a https page and you can't load/send to non secure origins while using https.我相信这是因为使用 cordova-android 10.0.x,webview 现在充当 https 页面,并且在使用 Z5E056C500A01C4B7BADE5Z101 时您无法加载/发送到非安全来源。

From the cordova docs来自 cordova 文档

By default, the WebViewAssetLoader is enabled and allows apps to serve their content from a 'proper' origin.默认情况下,WebViewAssetLoader 已启用,并允许应用从“正确”来源提供其内容。 This will makes routing work easily for frameworks like Angular.这将使路由对于 Angular 等框架更容易工作。

With no additional configurations, the app content is served from https://localhost/.在没有额外配置的情况下,应用程序内容从 https://localhost/ 提供。 You can configure the hostname by setting the preference option hostname.您可以通过设置首选项主机名来配置主机名。

   <preference name="hostname" value="localhost" />

The scheme, https, is not configurable by nature. https 方案本质上是不可配置的。

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

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