Okay, I’ve been poking about with AJAX, but have hit a snag with admin-ajax.php.
Whenever I send the call to admin-ajax.php I get a 400 error. I’ve tried calling to a test API online instead and the call went through.
This is in the HEAD of my html:
function swapVidGallery(newVidParam){
jQuery.get('/wp-admin/admin-ajax.php', {'action':'newVidGallery'}, function(response){
console.log(response)
jQuery('#vidGalleryContent').html(response);
});
}
Could there be something wrong with my admin-ajax.php? Does it need to be enqueued or initialized in any way? Could it have been corrupted, or might I just not have permissions?
Incidentally, the rest of my code is as follow, completely untested, of course, becasue I can’t get through to admin-ajax:
FUNCTIONS.HTML:
add_action('wp_ajax_newVidGallery', 'newVidGallery', 10, 1);
add_action('wp_ajax_nopriv_newVidGallery', 'newVidGallery', 10, 1);
function newVidGallery(newVidParam){
console.log("newVidGallery has been called:"+newVidParam)
if(newVidParam="UCIpxzcl4b3ggMODF6QnTOhQ"){
do_shortcode(vidShortcode+"searchResultsRestrictedToUser='"+newVidParam+"']");
} else {
do_shortcode(vidShortcode+"playlistValue='"+newVidParam+"']");
}
die();
}
HTML BODY:
<a href="swapVidGallery('UCIpxzcl4b3ggMODF6QnTOhQ')"> All Videos </a><br />
<a href="swapVidGallery('PLMffcFdm_7-Hi6NibMNpEuc8rlqbBNxC8')"> Did You Know? </a><br />
<a href="swapVidGallery('PLMffcFdm_7-HKkGlaF4AUByzzgnA_jsoD')"> Freezerworks 2017 & 2018 </a><br />
<a href="swapVidGallery('PLMffcFdm_7-HQF17XpQ-fb3lYWXlYHKDR')"> Base Edition </a><br />
-
This reply was modified 6 years, 8 months ago by
gyzhor.