2gis-maps
Version:
Interactive 2GIS maps API, based on Leaflet
91 lines (88 loc) • 3.28 kB
HTML
<h2 id="asynchronous-requests (ajax)">Asynchronous requests (AJAX)</h2><p><dl class="api-incut"><ul class="page-contents"><li><a href="#dgajax">DG.ajax</a><ul><li><a href="#methods">Methods</a></li><li><a href="#options">Options</a></li></ul></dl></p>
<h3 id="dgajax">DG.ajax</h3><p>The DG.ajax function allows to send cross-domain AJAX requests.</p>
<pre><code>var promise = DG.ajax('http://www.geonames.org/postalCodeLookupJSON', {
type: 'get',
data: {
postalcode: 10504,
country: 'US'
},
success: function(data) {
console.log('success', data);
},
error: function(error) {
console.log('error', error);
}
});
// to cancel the request:
// promise.abort();
</code></pre><h4 id="methods">Methods</h4><table>
<thead>
<tr>
<th>Method</th>
<th>Returns</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><b>DG.ajax</b>(
<nobr><String> <i>url</i>,</nobr>
<nobr><<a href="#options">Ajax options</a>> <i>options?</i> )</nobr>
</code></td>
<td><code>Promise</code></td>
<td>Sends a request to the server and returns a Promise object with the abort method,
with the help of which you can abort the sending of the request. Takes a URL as
input parameters, where we will send you a request and an optional object of options.</td>
</tr>
</tbody>
</table>
<h4 id="options">Options</h4><table>
<thead>
<tr>
<th>Option</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><b>data</b></code></td>
<td><code>Object</code></td>
<td><code>null</code></td>
<td>The data that will be sent to the server.</td>
</tr>
<tr>
<td><code><b>type</b></code></td>
<td><code>String</code></td>
<td><code>get</code></td>
<td>Type of request ('get', 'post' or 'jsonp').</td>
</tr>
<tr>
<td><code><b>success</b></code></td>
<td><code>Function</code></td>
<td><code>null</code></td>
<td>A function which is triggered in case of successful server response.
Takes the received data as a parameter.</td>
</tr>
<tr>
<td><code><b>error</b></code></td>
<td><code>Function</code></td>
<td><code>null</code></td>
<td>A function that is triggered when an error occurs.
Takes the error information as a parameter.</td>
</tr>
<tr>
<td><code><b>url</b></code></td>
<td><code>String</code></td>
<td><code>null</code></td>
<td>The URL to which the request will be sent.</td>
</tr>
<tr>
<td><code><b>timeout</b></code></td>
<td><code>Number</code></td>
<td><code>null</code></td>
<td>Query timeout (in milliseconds).</td>
</tr>
</tbody>
</table>