我创建了一个应用程序Android应用程序(批量短信)使用JavaScript,HTML,手机差距,该应用程序是为已建成的bulksms网站。 一切顺利但我尝试测试运行应用程序。当我登录时,它给我一个错误(连接到服务器的错误)。 index.html包含登录表单,其中包含登录参数,将其附加到API并加载menu.html文件。但是当我尝试登录时,index.html文件会出现上述错误
这是index.html文件代码
<html>
<head>
<title>ClicknSpread</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
<script src="cordova.js"></script>
<script src="js/jquery-2.0.0.js"></script>
<script src="js/main.js"></script>
<script src="js/index.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
function onDeviceReady() {
// Now safe to use device APIs
document.addEventListener("backbutton", onBackKeyDown, false);
var os = device.platform;
if(os == "Android") $(".quit").removeClass('hidden');
}
function onBackKeyDown() {
// Handle the back button
var os = device.platform;
if(os == "Android") {
if(confirm('Quit '+appname+'?')) navigator.app.exitApp();
}
}
</script>
</head>
<body onload="onLoad()">
<h1 class="title appname">Menu</h1>
<div class="page">
<h3> </h3>
<div class="login hidden center">Contacting Server...<br /><img src="images/loading.gif" /></div>
<div class="login">
<div class="form-container" style="width: 65%;">
<h3>Login</h3>
<div class="label">Username</div>
<input type="text" id="username" placeholder="Username" />
<div class="label">Password</div>
<input type="text" id="password" placeholder="Password" />
<div class="button-div">
<a href="#" onclick="login(); return false;" class="button">Login</a>
<a href="register.html" class="button register hidden">Register</a>
<a href="#" onclick="if(confirm('Quit '+appname+'?')){ navigator.app.exitApp(); } return false;" class="button quit hidden">Quit</a>
</div>
</div>
</div>
<div>
<div class="footer"></a>
</body>
</html>
这里是main.js文件,其中包含批量短信站点的API和域名.etc
api = 'http://clickspreadsmsz.com/index.php?option=com_spc&comm=spc_api&mobi=true&';
domain = 'www.clickspreadsmsz.com';
appname = 'ClicknSpread';
xOK = 'Operation completed successfully.';
x_2904 = 'SMS Sending Failed';
x_2905 = 'Username/Pasword combination is incorrect';
x_2906 = 'Credit Exhausted';
x_2907 = 'Gateway Unavailable';
x_2908 = 'Invalid Schedule Date';
x_2909 = 'Scheduling failed.';
x_2910 = 'Invalid Username';
x_2911 = 'Invalid Password';
x_2912 = 'Invalid recipient';
x_2913 = 'Invalid Message';
x_2914 = 'Invalid Sender ID';
x_2915 = 'One or more required fields are missing';
x_101 = 'Invalid voucher';
x_102 = 'Used voucher';
x_103 = 'Unable to load voucher';
x_106 = 'Invalid group name.';
x_107 = 'Operation failed.';
$(function (){
$('.appname').html(appname);
$('.domain').html(domain);
$('.footer').html('© '+domain+'.All rights reserved. Contact Us on +234(0)8088996437 ,+234(0)9096669196 info@bizmarrow.com, contact@clicknspreadsms.com ');
setFontSize();
});
function setSession(key,value){
window.localStorage.setItem(key, value);
}
function getSession(key){
return window.localStorage.getItem(key);
}
function unsetSession(key){
window.localStorage.removeItem(key);
}
function clearSession(){
window.localStorage.clear();
}
function setFontSize(){
var fs = getSession('fontsize');
if(fs == '' || !is_numeric(fs) || fs < 10){
fs = 16;
setSession('fontsize',fs);
}
$("html, body, .page, a, textarea, select").css("font-size", fs+"px");
$("h1").css("font-size", Math.floor(fs*1.4)+"px");
$("h2").css("font-size", Math.floor(fs*1.3)+"px");
$("h3").css("font-size", Math.floor(fs*1.2)+"px");
$("h4").css("font-size", Math.floor(fs*1.1)+"px");
$("input").css("font-size", fs+"px");
}
function is_numeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function isLoggedIn(){
var u = getSession('username');
var p = getSession('password');
if(u != '' && u != undefined && p != '' && p != undefined){
return true;
} else {
return false;
}
}
function nothing(){};
function balance(){
var u = getSession('username');
var p = getSession('password');
if(u != '' || u != undefined || p != '' || p != undefined){
} else {
logout();
}
$.get( api+'username='+escape(u)+'&password='+escape(p)+'&balance=true' )
.fail(function() {
alert( "Error connecting to server" );
})
.done(function(data) {
if(data == '2905' || data == '-2905'){
alert('Invalid username and password combination.');
logout();
} else {
$(".balance").html(number_format(0+data,2));
}
});
}
function logout(){
unsetSession('username');
unsetSession('password');
window.location = "index.html";
}
这是index.js文件代码,如果成功连接到API,则应加载menu.html文件。
$(function (){
$.get( api+'regMobile=check' )
.done(function(data) {
if(data == 'Enabled') $('.register').show(300);
});
});
function login(){
$('.login').toggle();
var username = $('#username').val();
var password = $('#password').val();
if(username == '') {
alert('Username is required');
$('.login').toggle();
return;
}
if(password == '') {
alert('Password is required');
$('.login').toggle();
return;
}
$.get( api+'username='+escape(username)+'&password='+escape(password)+'&balance=true' )
.fail(function() {
alert( "Error connecting to server" );
})
.done(function(data) {
if(data == '2905' || data == '-2905'){
alert('Invalid username and password combination.');
logout();
} else {
setSession('username',username);
setSession('password',password);
$('.login').toggle();
window.location = 'menu.html';
}
});
}
if(isLoggedIn() == true){
window.location = 'menu.html';
}
这是config.xml文件代码
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.smsportalcreator.demo"
versionCode = "4"
version = "4.0.0" >
<!-- versionCode is optional and Android only -->
<preference name="orientation" value="portrait" />
<name>ClicknSpread</name>
<icon src="icon.png" />
<description>
Mobile App for sending Bulk sms.
</description>
<gap:plugin name="cordova-plugin-device" spec="1.1.5" source="npm" />
<gap:plugin name="cordova-plugin-contacts" spec="2.3.0" source="npm"/>
<author href="http://smsportalcreator.com" email="uchejesse126@gmail.com">
JESSE CODERS
</author>
</widget>
我认为每件事情都是有序的,但在我使用phonegap构建之后,我仍然会收到错误(连接到服务器的错误)。如果需要更多文件,我可以添加它们。请帮助我如何解决错误并允许顺利连接和加载。