simple's Studio.

jQuery的`ajax()`方法

2017/11/18

.ajax() 方法 是整个 jQuery 库的异步请求的核心。你可以通过多种方式来调用 .ajax() 方法:

$.ajax(<url-to-fetch>, <a-configuration-object>);

// or 

$.ajax();
.ajax() 方法的最常用使用方式是使用配置对象,因为可以在配置对象中设置一切。

##什么是”配置对象”?##
配置对象是一个用来配置方法的普通 JavaScript 对象。例如:

var settings = {
   frosting: 'buttercream',
   colors: ['orange', 'blue'],
   layers: 2,
   isRound: true
};

…the settings configuration object can be used in the imaginary MakeCake constructor function:

const myDeliciousCake = MakeCake( settings );
Alternatively, the settings object could be passed in directly:

const myDeliciousCake = MakeCake({
   frosting: 'buttercream',
   colors: ['orange', 'blue'],
   layers: 2,
   isRound: true
});

进行 Ajax 调用
如果 jQuery 的 .ajax() 方法要支撑所有 jQuery 异步请求,则必须非常强大。以下是简单的 Ajax 请求:

$.ajax({
url: ‘http://swapi.co/api/people/1/
});

CATALOG