Static Methods
Get JSON data by jsonp
from https://gist.github.com/gf3/132080/110d1b68d7328d7bfe7e36617f7df85679a08968
Parameter |
Type |
Description |
url
|
String
|
resource url |
cb
|
function
|
callback function when completed |
(static) get(url, optionsopt, cb)
[source]
Fetch remote resource by HTTP "GET" method
maptalks.Ajax.get(
'url/to/resource',
(err, data) => {
if (err) {
throw new Error(err);
}
// do things with data
}
);
Parameter |
Type |
Default |
Description |
url
|
String
|
|
resource url |
options
opt
|
Object
|
null
|
request options
Properties
Parameter |
Type |
Default |
Description |
headers
opt
|
Object
|
null
|
HTTP headers |
responseType
opt
|
String
|
null
|
responseType |
credentials
opt
|
String
|
null
|
if with credentials, set it to "include" |
|
cb
|
function
|
|
callback function when completed |
Returns:
Ajax:
Ajax
(static) post(url, options, cb)
[source]
Fetch remote resource by HTTP "POST" method
maptalks.Ajax.post(
'url/to/post',
{
postData : {
'param0' : 'val0',
'param1' : 1
}
},
(err, data) => {
if (err) {
throw new Error(err);
}
// do things with data
}
);
Parameter |
Type |
Description |
url
|
String
|
resource url |
options
|
Object
|
request options
Properties
Parameter |
Type |
Default |
Description |
postData
|
String
|
Object
|
|
post data |
headers
opt
|
Object
|
null
|
HTTP headers |
|
cb
|
function
|
callback function when completed |
Returns:
Ajax:
Ajax
Fetch resource as arraybuffer.
maptalks.Ajax.getArrayBuffer(
'url/to/resource.bin',
(err, data) => {
if (err) {
throw new Error(err);
}
// data is a binary array
}
);
Parameter |
Type |
Default |
Description |
url
|
String
|
|
url |
options
opt
|
Object
|
null
|
options, same as Ajax.get |
cb
|
function
|
|
callback function when completed. |
(static) getJSON(url, optionsopt, cb)
[source]
Fetch resource as a JSON Object.
maptalks.Ajax.getJSON(
'url/to/resource.json',
{ jsonp : true },
(err, json) => {
if (err) {
throw new Error(err);
}
// json is a JSON Object
console.log(json.foo);
}
);
Parameter |
Type |
Default |
Description |
url
|
String
|
|
json's url |
options
opt
|
Object
|
null
|
optional options
Properties
Parameter |
Type |
Default |
Description |
jsonp
opt
|
String
|
false
|
fetch by jsonp, false by default |
|
cb
|
function
|
|
callback function when completed. |