Javascript 什么是jQuery';它相当于Ajax.Request,以及onSuccess和onComplete?
这是我的密码:Javascript 什么是jQuery';它相当于Ajax.Request,以及onSuccess和onComplete?,javascript,jquery,prototypejs,Javascript,Jquery,Prototypejs,这是我的密码: 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.come
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
。文档非常详尽:
类似于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
函数,但最好避免使用它们,因为它们对响应做出假设,这可能导致意外故障。其中一个函数是.ajax
。文档非常详尽:
类似于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
函数,但最好避免使用它们,因为它们会对响应做出假设,这可能导致意外的失败。在jQuery API中查找这一点很难吗?@charlietfl老实说,是的。在jQuery API中查找这一点很难吗?@charlietfl老实说,是的,好的,我自己发现的。啊,好的,我自己发现的。