我正在尝试通过以下链接使用D3提取将值发布到我的servlet:https://beta.observablehq.com/@mbostock/posting-with-fetch。 任何人都可以建议这里出了什么问题吗? -谢谢。
我的D3 Fetch语句如下:
d3.select('#myButton').on('click', function(){
d3.json("${pageContext.request.contextPath}/SomeServlet", {
body: JSON.stringify({"valuetosubmit": "test"}),
headers: {"content-type": "application/json"},
method: "POST",
mode: "cors"
})
});
从我的虚拟servlet中提取以下内容:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Map<String, String> options = new LinkedHashMap<>();
String searchno=request.getParameter("searchedPart");
System.out.println(searchno);
options.put("value1", "label1");
options.put("value2", "label2");
options.put("value3", "label3");
String data = new Gson().toJson(options);
System.out.println(data);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(data);
}
哪个抛出以下错误:未处理的承诺拒绝:错误:405