在另一页面的div元素上显示响应值

时间:2016-09-06 02:09:25

标签: jquery

从patient_detail_search.php成功获取ajax后,如何在patient_info.php中的div元素上显示值?

在patient_detail_search.php中搜索js

    $('.search').on('click', function(){
        var search_by = $('.search_lists').val();
        var search_text = $('.search_text').val();
        $.ajax({
            url: 'patient_search.php',
            type: 'POST',
            data: {patient_search_by: search_by, patient_search_text: search_text},
            success:function(response){
                //... Get response value to display on patient_info.php
            }
        });
    });

从patient_detail_search.php获取响应值,以显示在patient_info.php中的div元素

<div class="patient_detail_box">
    <!-- response value here -->
</div>

1 个答案:

答案 0 :(得分:0)

您可以使用.html()函数(jQuery doc here)或.text()函数(jQuery doc here)将内容插入元素中。在您的情况下,您可以尝试:

$('.search').on('click', function(){
    var search_by = $('.search_lists').val();
    var search_text = $('.search_text').val();
    $.ajax({
        url: 'patient_search.php',
        type: 'POST',
        data: {patient_search_by: search_by, patient_search_text: search_text},
        success:function(response){
            //... Send response value to class="patient_detail_box" on patient_info.php
            $('.patient_detail_box').html("Response from server: " + response);
        }
    });
});