php - wordpress dependent dropdownlist using post type is not working

admin2025-06-03  4

wordpress dependent drop down list using post type is not working in ajax.

I need a ddl value from another ddl in post type.

i have 2 post type department and doctors, when i select a department in drop down list i need the doctors in that department using ajax and not by refresh

ajax

$('#dpt').change(function () {
            var dpt = $(this).val();
            jQuery.ajax({
                type: 'post',
                data: {id: dpt},
                success: function (data) {   
//                    alert(data);
                    $('#response').text('dpt : ' + data);
                }
            });
        });

wordpress dependent drop down list using post type is not working in ajax.

I need a ddl value from another ddl in post type.

i have 2 post type department and doctors, when i select a department in drop down list i need the doctors in that department using ajax and not by refresh

ajax

$('#dpt').change(function () {
            var dpt = $(this).val();
            jQuery.ajax({
                type: 'post',
                data: {id: dpt},
                success: function (data) {   
//                    alert(data);
                    $('#response').text('dpt : ' + data);
                }
            });
        });
Share Improve this question edited Jan 31, 2019 at 9:41 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Jan 31, 2019 at 5:11 sanjaysanjay 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

PHP

Select Doctors 'doctors', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'dptmnt', 'value' => $dpt, 'compare' => 'LIKE' ), 'order' => 'ASC' ), ); $events = new WP_Query($args); while ($events->have_posts()): $events->the_post(); ?> ">

HTML

Select Department 'dpt', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC' ); $events = new WP_Query($args); while ($events->have_posts()): $events->the_post(); ?> ">

AJX

$(function () { $("select[name='dp']").change(function () { var str = ""; $("select[name='dp'] option:selected").each(function () { str += $(this).text() + " "; }); jQuery.ajax({ type: "POST", data: $("form#a").serialize(), success: function (data) { // alert(data); // jQuery(".res").html(data); $('#doc').html(data); } }); var str = $("form").serialize(); // $(".res").text(str); }); });

This work for me

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748942103a315019.html

最新回复(0)