2 elgg.provide(
'elgg.ajax');
20 options =
elgg.ajax.handleOptions(
url, options);
22 options.url =
elgg.normalize_url(options.url);
23 return $.ajax(options);
43 elgg.ajax.handleOptions =
function(
url, options) {
50 options = options || {};
59 if (
elgg.isFunction(options)) {
68 for (member in options) {
70 if (
elgg.isFunction(options[member])) {
79 options = {data: data};
82 if (!
elgg.isFunction(options.error)) {
84 options.error =
elgg.ajax.handleAjaxError;
102 elgg.ajax.handleAjaxError =
function(xhr, status,
error) {
103 if (!xhr.getAllResponseHeaders()) {
108 elgg.register_error(
elgg.echo(
'ajax:error'));
119 options =
elgg.ajax.handleOptions(
url, options);
121 options.type =
'get';
122 return elgg.ajax(options);
133 options =
elgg.ajax.handleOptions(
url, options);
135 options.dataType =
'json';
136 return elgg.get(options);
147 options =
elgg.ajax.handleOptions(
url, options);
149 options.type =
'post';
150 return elgg.ajax(options);
206 if (
action.indexOf(
'action/') < 0) {
210 options =
elgg.ajax.handleOptions(
action, options);
214 if (!
elgg.isString(options.data) || options.data.indexOf(
'__elgg_ts') == -1) {
215 options.data =
elgg.security.addToken(options.data);
217 options.dataType =
'json';
220 var custom_success = options.success ||
elgg.nullFunction;
221 options.success =
function(json, two, three, four) {
222 if (json && json.system_messages) {
223 elgg.register_error(json.system_messages.error);
224 elgg.system_message(json.system_messages.success);
227 custom_success(json, two, three, four);
230 return elgg.post(options);
249 elgg.api =
function (method, options) {
250 elgg.assertTypeOf(
'string', method);
257 options =
elgg.ajax.handleOptions(method, options);
258 options = $.extend(defaults, options);
260 options.url =
'services/api/rest/' + options.dataType +
'/';
261 options.data.method = method;
263 return elgg.ajax(options);
elgg message elgg state error
elgg message elgg state success
if(!$site) if(!($site instanceof ElggSite)) $site url