ajax function in wordpress returns -1 error help?
-
Hi I’m doing something wrong and I cant see what.
I’ve tried find a solution on the web for hours but doesn’t seem to work.
I like to post data to a wp loop and show the result (visual).
Its only shows a -1 (error) login in wp admin or not. If i call the code from external php file it works fine, but i need to use the loop.
-I’m using a WAMP server but if i test the scripts online ive got the same (-1 error?).
-I use the latest version of wp
What am I doing wrong here?From a wp theme file loaded in index.php:
$('#provinform').change(function() { var provinvieID = new Array(); $("#provinform :checked").each(function() {provinvieID.push($(this).val());}); $.ajax({ type: "POST", url: "<?php bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php", action : "my_special_action" , data: {'provincie': provinvieID}, success: function(result){ $('#here').html(result); } }); }); });In the functions.php:
` add_action(‘wp_ajax_my_special_action’, ‘my_special_action’);
add_action(‘wp_ajax_nopriv_my_special_action’, ‘my_special_action’);function my_special_action() {
print_r($_POST); //testing
echo ‘test’;
die();
}`
The topic ‘ajax function in wordpress returns -1 error help?’ is closed to new replies.