ajax load shortcode in response

时光毁灭记忆、已成空白 提交于 2020-12-15 05:06:43

问题


I have a form in a page-form.php file, on Sumbit i need to send the data to formResult.php to connect to db and get results (products IDs). With Ajax in the form.php file i need to load the products IDs in a shortcode like that : [product id="1, 2, 3"].

form.php part of getting the result from DB :

while( $row = mysqli_fetch_assoc($result) ) {
        echo $row["ID"]; // it does display the IDs in page-form.php
        echo do_shortcode('[product id="'.$row["ID"].'"]'); // if i add this line, nothing is shown ... the problem is here
    }
echo '</div>';

page-form.php part of getting the result from form.php

$(document).ready(function(){
        $('#repeater_form').on('submit', function(event){
            event.preventDefault();
            $.ajax({
                url:"/formResult.php",
                method:"POST",
                data:$(this).serialize(),
                success:function(data)
                {
                    $('#success_result').html(data);
                }
            })
        });

    });

来源:https://stackoverflow.com/questions/65190691/ajax-load-shortcode-in-response

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!