这是我的代码:
this.ajax = new Ajax.Request(this.url, {
method: 'get',
parameters: { 'timestamp' : this.timestamp },
onSuccess: function(transport) {
// handle the server response
var response = transport.responseText.evalJSON();
this.comet.timestamp = response['timestamp'];
this.comet.handleResponse(response);
this.comet.noerror = true;
},
onComplete: function(transport) {
// send a new ajax request when this request is finished
if (!this.comet.noerror)
// if a connection problem occurs, try to reconnect each 5 seconds
setTimeout(function(){ comet.connect() }, 5000);
else
this.comet.connect();
this.comet.noerror = false;
}
});
我主要想了解
onComplete
函数,这就是我正在考虑的内容。 最佳答案
.ajax
是此类功能之一。该文档非常详尽:jQuery .ajax function。onSuccess
和类似onComplete
的功能的示例可能是这样的...
$.ajax({
url: "test.php",
type: "post",
data: values,
success: function() {
alert("success");
},
error: function() {
alert("failure");
},
complete: function() {
alert("both success and error have been checked, request finished!");
}
});
也有单独的
.post
和.get
函数,但是最好避免使用它们,因为它们对响应进行了假设,并且可能导致意外的失败。关于javascript - jQuery和onSuccess和onComplete等效于Ajax.Request是什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14491649/