여기에서 서버에서 오는 C_id가 잘못된 경우 오류 기능이 작동하지 않는 이유를 모르겠습니다. 나는 서버 데이터베이스에서 C_id를 얻고 그 C_id를 ajax 요청에서 다른 서버로 전달하고 있습니다.
$.ajax
({
url: "http://proserve.ekspeservices.com/client.php",
type: "GET",
datatype: "json",
data: {type: 'login', id: C_id},// getting C_id from server, but here if C_id is incorrect error function is not working
ContentType: "application/json",
error: function()
{
navigator.notification.alert('inCorrect Key');
},
success: function(res)
{
var simpleJson = JSON.parse(res);
myDB.transaction(function (txe1)
{
for (var i = 0; i < simpleJson.User.length; i++)
{
var Cli_id= simpleJson.User[i].id;
myDB.transaction(function (txe)
{
txe.executeSql('CREATE TABLE Client_data(Mobile integer , C_id integer, U_id integer , name text , ip integer )');
});
myDB.transaction(function (txe1)
{
var data_ins = 'INSERT INTO Client_data (Mobile,C_id,U_id) VALUES (?,?,?)';
txe1.executeSql(data_ins, [p,C_id,U_id]
,function(tx, result)
{
navigator.notification.alert('Inserted' , onSignup, 'Info', 'ok');
},
function(error)
{
navigator.notification.alert('Already Registered');
});
});
}
});
}
});
먼저, 귀하의 경우 client_id
범위가 ftr () 내에 있는 변수에 액세스하려고 합니다.
따라서 액세스하려면 전역 적으로 정의해야합니다. 또한 한 번에 여러 값을 가져 오므로이를 푸시해야하므로 배열로 정의해야합니다. 귀하의 코드는 이와 같은 것입니다.
또한 당신은 호출 할 필요가 ab()
후 기능을 ftr()
실행 완료로 ab()
출력에 따라 달라집니다 ftr()
당신이 연기 jQuery로 이동하거나 호출 할 수 result.So ab()
내에서 ftr()
아래와 같이
var client_id = [];
function ftr()
{
myDB.transaction(function(transaction)
{
transaction.executeSql('SELECT * FROM User_data', [], function (tx, results)
{
var len = results.rows.length;
for (var i=0; i<len; i++)
{
var emp = results.rows.item(i);
client_id.push({
id: emp.C_id,
});
}
}, null);
});
ab();
}
function ab(){
console.log(client_id);
}
function onDeviceReady()
{
myDB = window.sqlitePlugin.openDatabase({name: "mydb.db", location: 'default'});
ftr();
}
질문이 있으면 알려주세요.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다