0

Нужно подгрузить контент из другого файла в div с классом .content

$('.pages_list a').click(function(e){
    e.preventDefault();
    var postId = parseInt( $(this).attr('data-catid') );
    postviewCountGet(postId);
});

function postviewCountGet(postId){  
   $.ajax({
    success: function(html){
        $( ".text" ).load( "/posts.php" );
        }
    });         
};

В корне сайта есть файл posts.php

<?php
  echo "result";
?>

Вот его содержимое нужно вывести в блок с классом .content. Выдает ошибку

jquery.js?ver=1.12.4:4 GET http://hitechbuld/posts.php 404 (Not Found)

На самом деле файл posts.php есть в корне сайта. Как этот вопрос решить в WordPress ?

5
  • Вот всё, что в success, только без всяких аяксов.
    – Kirill
    25 мар 2019 в 17:02
  • То есть так достаточно ?
    – Denis
    25 мар 2019 в 17:10
  • function postviewCountGet(postId){ $( ".text" ).load( "/posts.php" ); };
    – Denis
    25 мар 2019 в 17:10
  • Выдает ошибку GET hitechbuld/posts.php 404 (Not Found)
    – Denis
    25 мар 2019 в 17:11
  • Ошибка в пути к файлу.
    – Kirill
    25 мар 2019 в 17:13

2 ответа 2

1
$( ".text" ).load( "<? echo bloginfo('template_url') . '/posts.php'?>" );

Вот так сработало

1
  • + что не поленились дорешать задачу.
    – Kirill
    25 мар 2019 в 17:48
0
function postviewCountGet(postId){
    $(".content").load("/path/to/file");
};

В .content залетит всё из post.php.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.