admin管理员组文章数量:1434877
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 ''."}
I don't understand from where is it ing. I added required lines to the res/xml/config.xml
<access origin="*" />
<access uri="*" subdomains="true" />
<feature name=".0/network"/>
And the permission INTERNET in the AndroidManifest. But the error is still happening...
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.
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'."}
I don't understand from where is it ing. I added required lines to the res/xml/config.xml
<access origin="*" />
<access uri="*" subdomains="true" />
<feature name="http://api.phonegap./1.0/network"/>
And the permission INTERNET in the AndroidManifest. But the error is still happening...
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.
Share Improve this question asked Feb 11, 2015 at 11:29 Kyu_Kyu_ 8004 gold badges10 silver badges19 bronze badges 4-
jQuery.support.cors = true;
- why are you overriding jQuery's cors detection? If a browser doesn't support cors, then telling jQuery it does won't help with anything. – Quentin Commented Feb 12, 2015 at 17:09 -
1
Access-Control-Allow-*
are response headers, sent by the server. Sending these headers in your request may be what's ruining your request. I have limited experience with Cordova's cross-origin behavior, though, so I don't know for sure. – apsillers Commented Feb 12, 2015 at 17:10 - I added Jquery.support.cors and the 3 lasts setRequestHeader when I had my problem. It wasn't working before. – Kyu_ Commented Feb 13, 2015 at 11:57
- Does it work without the async option set to false? – Jack Vial Commented Sep 28, 2015 at 14:49
1 Answer
Reset to default -1The jQuery documentation states:
Returning false in the beforeSend function will cancel the request
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.
本文标签: javascriptFailed to execute 39send39 on 39XMLHttpRequest39Stack Overflow
版权声明:本文标题:javascript - Failed to execute 'send' on 'XMLHttpRequest' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745643670a2668006.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论