Title: ajax function in wordpress returns -1 error help?
Last modified: August 20, 2016

---

# ajax function in wordpress returns -1 error help?

 *  [dewortel](https://wordpress.org/support/users/dewortel/)
 * (@dewortel)
 * [15 years ago](https://wordpress.org/support/topic/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.

## Tags

 * [ajax](https://wordpress.org/support/topic-tag/ajax/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)

 * 0 replies
 * 1 participant
 * Last reply from: [dewortel](https://wordpress.org/support/users/dewortel/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/ajax-function-in-wordpress-returns-1-error-help/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
