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 =
function(xhr, status,
error) {
85 elgg.ajax.handleAjaxError(xhr, status,
error);
104 elgg.ajax.handleAjaxError =
function(xhr, status,
error) {
105 elgg.register_error(
elgg.echo(
'ajax:error'));
116 options =
elgg.ajax.handleOptions(
url, options);
118 options.type =
'get';
119 return elgg.ajax(options);
130 options =
elgg.ajax.handleOptions(
url, options);
132 options.dataType =
'json';
133 return elgg.get(options);
144 options =
elgg.ajax.handleOptions(
url, options);
146 options.type =
'post';
147 return elgg.ajax(options);
203 if (
action.indexOf(
'action/') < 0) {
207 options =
elgg.ajax.handleOptions(
action, options);
211 if (!
elgg.isString(options.data) || options.data.indexOf(
'__elgg_ts') == -1) {
212 options.data =
elgg.security.addToken(options.data);
214 options.dataType =
'json';
217 var custom_success = options.success ||
elgg.nullFunction;
218 options.success =
function(json, two, three, four) {
219 if (json && json.system_messages) {
220 elgg.register_error(json.system_messages.error);
221 elgg.system_message(json.system_messages.success);
224 custom_success(json, two, three, four);
227 return elgg.post(options);
246 elgg.api =
function (method, options) {
247 elgg.assertTypeOf(
'string', method);
254 options =
elgg.ajax.handleOptions(method, options);
255 options = $.extend(defaults, options);
257 options.url =
'services/api/rest/' + options.dataType +
'/';
258 options.data.method = method;
260 return elgg.ajax(options);
elgg message elgg state success
elgg message elgg state error
if(!$site) if(!($site instanceof ElggSite)) $site url