select标签"selected", true页面怎么不显示对应的option

$(function(){
$("#pcodeSelectId").on("change",function(){
var pcode = $("#pcodeSelectId").find("option:selected").val();
console.log("pcode--"+pcode);
$.ajax({
type: "get",
url: "http://127.0.0.1:8080/smw/item/getItemByPcode",
data: {pcode:pcode},
success: function(msg){
msg = eval(msg);
$("#pcodeSelectId option").each(function (index,doEle) {
if($(doEle).val() != msg.pcode){
$(this).attr("selected", false);
}else{
$(this).attr("selected", true);
}
});
$("#pnameSelectId option").each(function (index,doEle) {
if($(doEle).val() != msg.pname){
$(this).attr("selected", false);
}else{
$(this).attr("selected", true);
}
});
$("#pnameSelectId option[value='"+ msg.pname +"']").attr("selected",true );
$("#pcodeSelectId option[value='"+ msg.pcode +"']").attr("selected", true);
},
error:function(msg){
alert("请求失败");
}
});
});

$("#pnameSelectId").on("change",function(){
    var pname = $("#pnameSelectId").find("option:selected").val();
    console.log("pname--"+pname);
    $.ajax({
        type: "post",
        url: "http://127.0.0.1:8080/smw/item/getItemByPame",
        data: {pname:pname},
        success: function(msg){
            msg = eval(msg);
             $("#pcodeSelectId option").each(function (index,doEle) {
                    if($(doEle).val() != msg.pcode){
                        $(this).attr("selected", false);
                    }else{
                        $(this).attr("selected", true);
                    }
             });
             $("#pnameSelectId option").each(function (index,doEle) {
                    if($(doEle).val() != msg.pname){
                        $(this).attr("selected", false);
                    }else{
                        $(this).attr("selected", true);
                    }
             });
            $("#pnameSelectId option[value='"+ msg.pname +"']").attr("selected", true);
            $("#pcodeSelectId option[value='"+ msg.pcode +"']").attr("selected", true);
        },
        error:function(msg){
            alert("请求失败");
        }
    });

});

});

一次get一次post,不知道你放两次代码的意义,这个时候,起码要放相关html吧?ajax目前在被fetch逐渐取代,ajax中data,应该就看作一个字符串,
所以一般会JSON.stringify(obj),后台代码也不知道,你这样描述问题,合适吗?