无法执行'发送'上'XMLHtt prequest“ [英] Failed to execute 'send' on 'XMLHttpRequest'

查看:995
本文介绍了无法执行'发送'上'XMLHtt prequest“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在被使用AJAX一个科尔多瓦应用程序。我的问题是,在调试,应用程序工作正常。但是,当我建立一个发布,我得到了错误:

I'm working on a Cordova application which is using ajax. My problem is that in debug, the app is working. But when I build a release, I got the error :

{"readyState":0,"status":0,"statusText":"NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://sub.domain.tld'."}

我不从哪里飘过来理解。 我添加所需行至RES / XML / config.xml中

I don't understand from where is it coming. I added required lines to the res/xml/config.xml

<access origin="*" />
<access uri="*" subdomains="true" />
<feature name="http://api.phonegap.com/1.0/network"/>

和允许上网的Andr​​oidManifest。但错误仍在进行之中......

And the permission INTERNET in the AndroidManifest. But the error is still happening...

呵呵,这是我的ajax调用:

And oh, here is my ajax call:

jQuery.support.cors = true;
        $.ajax(
            {
                accepts: {
                    xml: "text/xml; charset=ISO-8859-1",
                    text: "text/plain; charset=ISO-8859-1"
                }
                , converters: {
                "text xml": jQuery.parseXML
            }
                , type: "POST"
                //, contentType: "text/xml; charset=ISO-8859-1"
                , contentType : "application/x-www-form-urlencoded; charset=iso-8859-1"
                , url: address
                , async: false
                , cache: false
                , crossDomain: false
                , data: msg
                , dataType: "text"
                , global: false
                , ifModified: false
                , username: this.params.server.login
                , password: this.params.server.pass
                , timeout: 500000
                , beforeSend: function(jqXHR) {
                    jqXHR.overrideMimeType('text/xml;charset=iso-8859-1');

                    jqXHR.setRequestHeader("Access-Control-Allow-Origin", "*");
                    jqXHR.setRequestHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
                    jqXHR.setRequestHeader("Access-Control-Allow-Methods","POST, GET, OPTIONS, DELETE, PUT, HEAD");
                }
            }
        )

希望你能帮助我找到一个解决方案。

Hope you'll be able to help me find a solution.

推荐答案

jQuery的文档声明:

在beforeSend函数返回false将取消该请求

Returning false in the beforeSend function will cancel the request

由于您的 beforeSend 函数没有返回语句,将返回未定义这是falsy。我认为取消你的要求(虽然我没有测试它)。尝试返回 beforeSend 函数结束。

Since your beforeSend function doesn't have a return statement it will return undefined which is falsy. I assume that cancels your request (even though I didn't test it). Try returning true at the end of your beforeSend function.

这篇关于无法执行'发送'上'XMLHtt prequest“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆