In functions.php I have:
function testajax() {
echo "test";
exit;
}
add_action('wp_ajax_testthisajax', 'testajax');
add_action('wp_ajax_nopriv_testthisajax', 'testajax');
In scripts.js I have:
$("#thisformsid").submit( function() {
$.ajax({
url: CustomAjax.ajaxurl,
type: "POST",
data: {
action: 'testthisajax'
},
success: function(result){
console.log('success: ', result);
},
error: function(xhr){
console.log(xhr.status);
},
complete: function(result){
console.log('complete: ', result);
}
})
});
My form is using the correct id and I can reach the ajax submit in my scripts.js file
The url is defined in scripts.js like:
var CustomAjax = {
ajaxurl: "/wp-admin/admin-ajax.php"
};
However this fails. In console I see an error and the value "0" returned. ANy ideas why this would not work? It seems like this, as basic as it is, should not error out but I don't see the problem. Any ideas?
Update: In console I see that the error is labeled as being on line 18 of my install of jquery (it's minified so i don't know what is actually at that line)? Why would there be an issue with jquery?