Submit ajax request on wordpress page

I have a single.php file in my theme folder and I use ajax code in this file. I have another file in the same folder where I get this request, but it does not work for me here, this is my jquery written in single.php

$na= jQuery.noConflict(); $na(document).ready(function(){ $na('nav a').click(function(){ var nv=$na(this).text().replace(/\s/g, "_"); var pv=nv.toLowerCase(); $na.ajax({ type: "POST", url: '<?php bloginfo('template_url')?>/popupdatapdf.php', data: 'valueMin='+pv, success: function(result){ alert(result); } }); }); 
+4
source share
1 answer

Try something like this:

 jQuery(function($){ $('nav a').on('click', function(){ var nv = $(this).text().toLowerCase().replace(/\s+/g, "_"); $.ajax({ type: "POST", url: '<?php echo get_template_directory_uri(); ?>/popupdatapdf.php', data: {valueMin : nv} }).done(function(result) { console.log(result); }); }); }); 

And open the console to check for errors, as the Networks tab to see that the file popupdatapdf.php really found in the root of the current theme.

+2
source

Source: https://habr.com/ru/post/1485995/


All Articles