ajax跨域请求springBoot后台

mac2025-07-06  8

-----------ajax代码----------------- $.ajax({ url: utils.getManagUrl+"/doctorController/selectdepartment",//远程url data: {"page": 1,"limit":10000,"unitId":unitId}, dataType: "json", xhrFields:{withCredentials: true}, type: "post", //async: false, success: function (data) { $.each(data.data, function (index, item) { if(item.id==dptid){ $('#departmentId').append("<option value="+item.id+" selected>"+item.depName+"</option>");// 下拉菜单里添加元素 }else{ $('#departmentId').append("<option value="+item.id+">"+item.depName+"</option>");// 下拉菜单里添加元素 } }); layui.form.render("select"); }, error: function () { layer.msg('失败'); }, }); ---------------后台----------------------- @RestController @CrossOrigin(origins="*",allowCredentials="true")//origin="*"代表所有域名都可访问 @RequestMapping("/doctorController")
最新回复(0)