0
我試圖建立某種形式的AJAX連接檢查的對象,但由於某種原因,我只是不能得到它的工作:/阿賈克斯連接檢查對象沒有返回值
對象:
function conn(data){
this.conn = false,
this.check = function(data){
if(data){
console.log("data: "+data)//Returns true
this.conn = data;
} else {
this.callServer();
}
},
this.callServer = function(){
$.get(ApiUrl("online"))
.done(function(data){})
.fail(function(data){})
.always(function(data){var c = new conn();c.check(data)});
}
}
用法:
var code = $(".login-form input#pincode").val();
var con = new conn();
con.check();
console.log("connection: "+ con.conn); // returns false
code = code.match(/[0-9]/g);
if (code === null || code.length !== 6) {
Alert("De code moet bestaan uit zes cijfers");
} else {
if(con.conn === true){
//Do stuff
}
函數 'ApiURL' 是創建了該URL所以不介意功能
你可以調用con.check();沒有數據參數 – Max
它有一個if語句。 –