2020-10-21笔记 ajax

it2024-02-22  68

Document 对象可以访问 HTML 页面中的所有元素。

ajax()方法通过 HTTP 请求加载远程数据。

$.ajax({ type: 'get', //请求方式 url: "/layerlist.ashx", //发送请求的地址?? dataType: "json", //预期服务器返回的数据类型 async: false, //同步请求 data: { //发送到服务器的数据 "type": "mapInfoQuery", "mapid": mapid }, success: function (data) { //返回json结果 //console.log(data); resolve({ type: "1", mapid: mapid, layerid: data.basemap }) } });

参数:

type(请求方式)

类型:String   默认值: "get"

url(发送请求的地址)

类型:String   默认值: 当前页地址。

dataType(预期服务器返回的数据类型)

类型:String

async(异步)

类型:Boolean   默认值: true

默认设置下,所有请求均为异步请求。如果需要发送同步请求,请将此选项设置为 false。

注意,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行。

data(发送到服务器的数据)

类型:String

发送到服务器的数据。将自动转换为请求字符串格式。GET 请求中将附加在 URL 后。

success(请求成功后的回调函数)

类型:Function

参数:由服务器返回,并根据 dataType 参数进行处理后的数据;描述状态的字符串。

这是一个 Ajax 事件。

最新回复(0)