0
votes

I have problem with using ajax in wordpress theme. I read all google first 5 pages and forum...i stucked.

So, i just in functions.php add these lines

function my_action_callback(){
    echo"aha";
    die();
}
add_action('wp_ajax_my_action', 'my_action_callback');
add_action('wp_ajax_nopriv_my_action', 'my_action_callback');

and in my theme file - main.js add on click event, which send ajax call.

$('.load_more').click(function(){ $.ajax({
type: 'POST',
url: 'http://www.mysite.eu/wp-admin/admin-ajax.php',
data: { action: 'my_action'}, success: function(data, textStatus, XMLHttpRequest){
alert('done');
},
error: function(MLHttpRequest, textStatus, errorThrown){
alert('error:'+errorThrown);
}
}); });

and i always get - 'error:' with empty textStatus. WHY?? please, help me :(

1

1 Answers

0
votes

Your textStatus is not defined, just change the data parameter like this:

data: { action: 'my_action', textStatus: $('.other_div').val },

And now you will get no errors.