Article From:https://segmentfault.com/q/1010000013010668
Question:

1

$.ajax({
  url: "/path/to/file",
  type: "default GET (Other values: POST)",
  dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
  data: { param1: 'value1' },
  success: function() {
    console.log("success");
  },
  error: function() {
    console.log("error");
  }
});

2

$.ajax({
  url: '/path/to/file',
  type: 'default GET (Other values: POST)',
  dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
  data: {param1: 'value1'},
})
.done(function() {
  console.log("success");
})
.fail(function() {
  console.log("error");
})
.always(function() {
  console.log("complete");
});

Answer 0:

The above is the traditional way of writing, the following is asynchronous writing, usually more flexible than the above, for example, you can write several..done()Callbacks will be clearer logically and very similar to chain writing.

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *