Returning content via jQuery without footers on admin pages

I am writing a plugin (github link) that allows the user to upload files in the admin-pages of wordpress.

I am running into an issue however: I created an upload form that essentially posts to itself and loads the contents of the result via AJAX (jQuery) inside the already loaded page.

The issue is that any content that is returned via URL of an admin page always has the footer of the page attached to it.

How can I return contents through an ajax call without those?

Solutions Collecting From Web of "Returning content via jQuery without footers on admin pages"

What you want to do is define a callback function to handle your request and to do that you need to hook onto:


…where “(action)” is the name of your “action” parameter that needs to be supplied in your AJAX request (more on that in a moment).

First, define a callback function in your PHP logic, let’s use the example of unc_gallery_upload.

In this case, “unc_gallery_upload” is the name of your action, so when defining your hook, you combine wp_ajax_ with unc_gallery_upload, and you get wp_ajax_unc_gallery_upload, that’s the name of your action hook.


function unc_gallery_upload_handler() {
    //handle request e.g. var_dump($_POST['data']);

add_action( 'wp_ajax_unc_gallery_upload', 'unc_gallery_upload_handler' );


In your AJAX request (JS code)

var options = {
    //this will post to
    //the ajaxurl variable is already defined in the global
    //scope of the WordPress dashboard
    url: ajaxurl,
   //your payload, accessible on $_POST['data']
    data: {
        //this name of your action as defined in your wp_ajax_(action)
        //hook that will fire your
        action: 'unc_gallery_upload',
        payload: 'somedata'
    target: '#targetLayer',
    beforeSubmit: beforeSubmit,
    uploadProgress: uploadProgress,
    resetForm: true,
    complete: complete

$('#uploadForm').submit(function() {
    return false;

I strongly recommend reading: wp_ajax_(action)

Note: since you are in the admin the area, you do NOT want to define a wp_ajax_nopriv_(action).