## Ajaxify v0.1

• what a fantastic idea! just a question though, what does elgg.action do?

• does it work with 1.7.1 version

• Really good idea, it would be great if they could make it an standard plugin or even part of the core.

• @stringbeans -- elgg.action will call the specified action via ajax.  So in the example given, the specified entity would be deleted.

@Rakesh -- elgg.echo, elgg.register_error, and elgg.system_message should work on any version.

@Fitosan -- actually, I am working with Brett on doing just that for 1.8.

• @evan you're doing an amazing work along with brett and the elgg team, keep it up man!

• hey evan,

with elgg.action i notice that there's no callback? could you possibly add in a parameter for a callback function (i guess so its similar to jQuery's $.post function) what do you think? or perhaps elgg.action has a different purpose? • forget my comment above, i should've actually looked at the code :) for those wondering, here's a snippet of the code commenting! * @example Usage 3: * Of course, you will have no control over what happens when the request * completes if you do it like that, so there's also the most verbose method * <pre> * elgg.action('friend/add', { * data: { * friend: some_guid * }, * success: function(json) { * //do something * }, * } * </pre> * You can pass any of your favorite$.ajax arguments into this second parameter.

• :) glad you found the documentation useful.

• Nice work, same as @Fitosan comment. This would be a good addition as a standard elgg plugin and provide some needed standardisation of elgg/ajax plugins. I know i'd make some use of this if it came with elgg.

• @Milan -- I'm working with Brett and trying to get this, or at least some of it, into the 1.8 core.

• I hope it will be included in newer version of Elgg :) Thanks for the plugin!

• Hi Evan, thank you so much for this contribution! and congratulations for get it ported to the core =)

I just want let you know I found some kind of bug; seems there is a trouble in the elgg.action function.

The situation is as following:

I have an elgg.action request with a "success" function on it's options, but the function doesn't get called when the request ends.  I worked around by modifying your code ending like this:

...181 |

//Always display system messages after actions

var custom_success = options.success || function(){};

options.success = function(json, two, three, four) {

if(typeof json == "object" && typeof json.system_messages == "object"){

if(typeof json.system_messages.errors != "undefined"){

elgg.register_error(json.system_messages.errors);

}

if(typeof json.system_messages.messages != "undefined"){

elgg.system_message(json.system_messages.messages);

}

}

custom_success(json, two, three, four);

};

Without those "ifs" my FF doesn't call "custom_success" function.

Hope this help, let me know if you need more details or I can help you somehow.

Cheers!

• Great plugin. I've been playing with this and have modified Facebox to work via elgg Ajaxify for ajax popup dialogs.

I found one bug in ajaxify which was very frustrating and took ages to track down. Maybe it only affects certain versions of PHP. If your ajax responses are always coming back with the content 'null' unless the content is JSON, look for these lines in start.php:

try {

$output = json_decode($output);

} catch(Exception $e) {} change them to try {$decodedoutput = json_decode($output); } catch(Exception$e) {}

if ($decodedoutput!='')$output=\$decodedoutput;

That should fix it! It seems json_decode can return an empty string for non-json, instead of throwing an error as the original script assumes it will.

• @chris

I was almost driven mad by that error, searching for hours to find it.

Thank you

### Evan Winslow

Software Engineer at Google. Elgg enthusiast. I wrote the Javascript and CSS frameworks for 1.8.

### Stats

• Category: Tools