Skip to content
Advertisement

Function echos variable correctly to ajax file but in html doesn’t show anything

Php variable $testing correctly echos ajax file, but in html <?php echo $testing;?> doesn’t show anything.

html:

JavaScript

functions.php:

JavaScript

Advertisement

Answer

The solution is to add $('#featured-image').html(data); to the script, which pass the data output to html.

JavaScript

also moved php lines from html to function.php:

JavaScript

I missunderstood how ajax works. The simplest answer imo is this diagram: enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement