android - 加载资源失败:net::ERR_CONNECTION_REFUSED Cordova android
问题描述
我正在使用cordova开发一个android应用程序,我在调用api时遇到了以下问题,请帮我解决这个问题
Failed to load resource: net::ERR_CONNECTION_REFUSED(http://ip address:8080)
var uName = $('#UserName_input').val();
var pwd = $('#Password_input').val();
console.log("GetLogin function CallED~~~~~~~~~~~~~");
console.log("GetLogin InternetStatus ~~~~~~~~~~~~~" + InternetStatus);
console.log("GetLogin function uNam~~~~~~~~~~~~~" + uName);
console.log("GetLogin function pwd ~~~~~~~~~~~~~" + pwd);
if (InternetStatus == 'Online') {
if (uName != "" && pwd != "") {
//SpinnerDialog.show("Loading", "Please Wait...", true);
$(".modal").show();
/*---------->*/
// alert("call before AJAX------>");
debugger
$.ajax({
url: baseURL + checkLogin,
type: 'POST',
data: {
'userName': uName,
'password': pwd
},
// ~~~~~~~~~~~~~~~~~ Basic autherntication ~~~~~~~~~~~~~~~~~~~~~~~~
/* beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("crewMobieAppAdmin" + ":" + "!uT#61@c#"));
},*/
success: function(result)
//we got the response
{
//debugger
console.log("message------>" + result.message + " \n status----->" + result.status);
//console.log(JSON.stringify(row));
if (result.status == "success") {
UserDatails(uName, result.tokenId);
ToastShow("Login Successfully.!!!", "#008000", "#FFFFFF");
USERNAME_localStorage_SET(uName);
PASSWORD_localStorage_SET(pwd);
BASEAUTH_localStorage_SET(result.tokenId);
PIN_localStorage_SET("");
SpinnerDialog.hide();
window.location.href = "home.html"
//$(".modal").hide();
} else {
SpinnerDialog.hide();
ToastShow(result.message, "#FF0000", "#FFFFFF");
// $(".modal").hide();
}
//SpinnerDialog.hide();
// $(".modal").hide();
},
error: function(exception) {
ToastShow("Server not responding. Please try again after some time.!!!", "#FF0000", "#FFFFFF");
console.log('Exception:' + exception);
status = "failur"
// Hide spinner dialog
//SpinnerDialog.hide();
// $(".modal").hide();
}
}) /*<----------*/
// SpinnerDialog.hide();
} else {
ToastShow("Please enter valid username and password.!!!", "#FF0000", "#FFFFFF");
}
} else {
ToastShow("please check your network connection and try again.!!!", "#FF0000", "#FFFFFF");
}
解决方案
这可能是版本兼容性问题。在此处查看类似问题的答案
否则,这可能是因为您在应用程序中阻止了 API URL。在 config.xml 中设置以下值
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
注意:这不是推荐的生产设置。如果此解决方案适合您,请考虑微调您的 URL。有关如何配置此功能的更多详细信息,请参阅Whitelisting URLS - Cordova 文档。
推荐阅读
- node.js - 在 nodeJs 中监听一个 url
- javascript - UTC 天数到本地时区天数
- python - Keras 包裹图层并保存
- php - Ajax 代码无法将我带到正确的页面
- react-native - 具有两列的容器:第一个具有固定宽度,第二个具有 flex grow
- reactjs - recharts折线图未呈现
- javascript - 如何在 JEST 中测试并行的模拟数据请求,同时以 500 毫秒的阈值模拟缓存响应
- oracle - 如何使用 oracle 在没有数据的情况下生成脚本(就像我们在 sql server 中所做的那样)?
- python - 如何在“https://www.drugs.com/”的所有html文件的标题下刮掉与ID相关的ID和文本?
- python - 如何在 numpy 选择概率中重复一个值