Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 什么是jQuery';它相当于Ajax.Request,以及onSuccess和onComplete?_Javascript_Jquery_Prototypejs - Fatal编程技术网

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老实说,是的,好的,我自己发现的。啊,好的,我自己发现的。