1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- (function () {
- var endpointSelector = new DevExpress.EndpointSelector(Partials.config.endpoints);
- function handleServiceError(error) {
- if (window.WinJS) {
- try {
- new Windows.UI.Popups.MessageDialog(error.message).showAsync();
- } catch (e) {
- }
- } else {
- alert(error.message);
- }
- }
- $.support.cors = true;
- Partials.api = Partials.api = {
- url: endpointSelector.urlFor("api"),
- errorHandler: handleServiceError,
- post: function (apiName, postData, parameters) {
- var url = this.makeApiUriWithParameters(apiName, parameters);
- var promise = $.ajax({
- url: url,
- dataType: 'json',
- contentType: 'application/json',
- method: "POST",
- data: JSON.stringify(postData)
- });
- promise.fail(handleServiceError);
- return promise;
- },
- get: function (apiName, parameters) {
- var url = this.makeApiUriWithParameters(apiName, parameters);
- var promise = $.ajax({
- url: url,
- method: "GET",
- });
- promise.fail(handleServiceError);
- return promise;
- },
- makeApiUriWithParameters: function (apiName, parameters) {
- var uri = [this.url, '/'];
- uri.push(apiName);
- if (typeof parameters === 'object') {
- uri.push('?');
- $.each(parameters, function (name, value) {
- if (value == null) return true;
- uri.push('&');
- uri.push(name);
- uri.push('=');
- uri.push(value);
- });
- }
- return uri.join('');
- },
- }
- }());
|