I make ajax request that returns data from Word Press .

But as a result, nothing returns to me.

PS: The paths are correct.

Code:

Js:

 function ct (x) { $("div.backgroundin").empty() var xhr = new XMLHttpRequest(); xhr.open('GET', '/wp-content/themes/bs/mods/category.php?ct='+x, true); xhr.send(); xhr.onreadystatechange = function () { if (xhr.readyState != 4) return; alert( xhr.responseText ); $("div.backgroundin:empty").html(xhr.responseText); } } 

PHP:

 <?php include('../../../../wp-load.php'); $x = $_GET['ct']; if ( have_posts() ) : query_posts('cat=4'); while (have_posts()) : the_post(); ?> <div class="card" id="card-s"> <div class="card-img-top img-fluid"><?php the_post_thumbnail(array(318,180)); ?></div> <div class="card-body" id="card-body-s"> <h4 class="card-title"><?php the_title(); ?></h4> <p class="card-text"><?php the_excerpt(); ?></p> <a href="<?php the_permalink(); ?>" class="btn btn-primary">Читать дальше</a> </div> </div> <?php endwhile; endif; wp_reset_query(); ?> 
  • one
    This is where you saw such Ajax with wp? Where are the hooks? Start reading from here wp-kama.ru/id_2018/ajax-v-wordpress.html - KAGG Design
  • one
    Like any big system, WordPress has its own rules. Learn to use them for a start, and then write your own. So far I have been seeing code that is completely impossible to maintain in a team. - KAGG Design
  • one
    In that all instructions are violated. When fuel is poured into the engine instead of a gas tank, it ends badly because the instructions have not been read. - KAGG Design
  • one
    @KAGGDesign, ajax in WP generally works fine bypassing admin-ajax and hooks. If the topic of the starter is not working, then the reason is something else - alenkins
  • 2
    No, the resource is not for that. I told you in the first comment what to do. You insist on the "debug my code for me" option. Read the rules, this is not welcome. Take phpStorm + xdebug in your hands and debug. Here is a knowledge base, and only questions that help other people make sense. - KAGG Design

0