我已經在javascript中註冊了ajax操作腳本。這裏是腳本=>ajax oop結果控制器
function AjaxConstruct(method,file,params){
this.method = method;
this.file = file;
this.params = params;
this.http = false;
}
AjaxConstruct.prototype.ajax = function(){
if (window.XMLHttpRequest){
this.http = new XMLHttpRequest();
} else {
this.http = new ActiveXObject("Microsoft.XMLXHTTP");
}
if (this.http){
this.http.open(this.method,this.file,true);
if (this.method==="POST"){
this.http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}
this.http.send(this.params);
this.http.onreadystatechange = function(){
if (this.http.readyState==4 && this.http.status==200){
alert("ok");
} else {
alert("no");
}
};
}
};
和創建對象像=>
var ajax = new AjaxConstruct("POST","filename","params"); // define object
ajax.ajax(); // invoke method
一切都可以正常使用,但只是我想知道我可以在OOP腳本標誌時,結果是好的,當它不是 ? 而且我對有多少數據是通過ajax發送感興趣還是無關緊要?例如,我想從七個輸入表單發送數據到mysql數據庫,在使用像這樣的ajax腳本發送期間是否有機會丟失數據?謝謝:)
我已經猜到誤差和上面的腳本糾正,感謝的人:)
不,你不會丟失發佈的請求中的數據。但是可能會發生數據包丟失。這就是爲什麼有一個響應代碼...(http狀態) – Sebas
我現在已經替換,它不提供警報,但ajax腳本工作,它發送數據到MySQL數據庫就好了,我不明白是怎麼回事: ( – tnanoba
也有一些東西:它可能不是問題,但只有當你發送郵件時你需要發送參數。如果你通過GET發送,params應該被添加到文件url,然後發送(null) ; – Sebas