The following is the jQuery function that loads the ajax:
function mediablender_attachment_ajax( att_id, display ) {
// Create the data to pass
var data = {
action: 'mediablender_structure',
type: settings.type,
att_id: att_id,
title: settings.show_titles,
description: settings.show_descriptions,
comments: settings.show_comments,
width: settings.width-settings.sidebar_width,
height: settings.height,
security: settings.security
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
ajax = jQuery.post( ajaxurl, data, function( response ) {
if( settings.type == 'lightbox' || settings.type == 'slider' ) {
if( display == true ) {
mediablender_attachment_display( response, att_id );
}
// If the attachment is an image, preload the image
var $temp = jQuery(response).find('.mediablender-attachment').children();
if( $temp.is('img') ) {
$temp.load( function() {
preloaded_attachments.push( {id:att_id, data:response} );
var next_id = mediablender_attachment_preload();
if( next_id ) {
mediablender_attachment_ajax( next_id, false );
}
});
} else {
preloaded_attachments.push( {id:att_id, data:response} );
var next_id = mediablender_attachment_preload();
if( next_id ) {
mediablender_attachment_ajax( next_id, false );
}
}
} else {
mediablender_attachment_display( response, att_id );
}
});
}
... and here is a snippet of the php function that is being loaded:
function mediablender_structure() {
// Get access to the database
global $wpdb;
// Check the nonce
check_ajax_referer( 'm4c_ajax_file_nonce', 'security' );
// Get variables
$att_id = $_POST['att_id'];
$type = $_POST['type'];
$title = $_POST['title'];
$description = $_POST['description'];
$comments = $_POST['comments'];
$width = ( $_POST['width'] != 0 ) ? $_POST['width'] : false;
$height = ( $_POST['height'] != 0 ) ? $_POST['height'] : false;
.... rest of the function ....
die(); // this is required to return a proper result
}