Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: [Resolved] adding new select field with group members as a value dynamically

@kiciana

Participant

Thanks for that. I read through it and I wanted to add the example function for admin footer to my plugin to check how it works but it crashes wordpress when I try to access the Dashboard.

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

I used this code:

<?php
add_action( 'admin_footer', 'my_action_javascript' ); // Write our JS below here

function my_action_javascript() { ?>
	<script type="text/javascript" >
	jQuery(document).ready(function($) {

		var data = {
			'action': 'my_action',
			'whatever': 1234
		};

		// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
		$.post(ajaxurl, data, function(response) {
			alert('Got this from the server: ' + response);
		});
	});
	</script> <?php
}
<?php 

add_action( 'wp_ajax_my_action', 'my_action_callback' );

function my_action_callback() {
	global $wpdb; // this is how you get access to the database

	$whatever = intval( $_POST['whatever'] );

	$whatever += 10;

        echo $whatever;

	die(); // this is required to terminate immediately and return a proper response
}

Any ideas what goes wrong here?

Skip to toolbar