关于XHR的问题,新人很困惑,为什么获取不到报404

就是这样子,今天突然就获取不到了
这个是后台代码
public static String doGet(String meraccount,String sale_count)
throws ServletException, IOException {
StringBuffer resultBuffer = new StringBuffer();
try {
JSONObject obj = new JSONObject();
obj.put("meraccount",meraccount);
obj.put("method", "queryRstation");
obj.put("v", "1.0");
obj.put("sale_count", sale_count);
obj.put("timestamp", System.currentTimeMillis());
String param_key = encrypt(
URLEncoder.encode(obj.toString(), "UTF-8"),
PUBLICKEY);
String secret_key = URLEncoder.encode(
MD5(paramSort(obj)), "UTF-8");
ClientResource client = new ClientResource(
"http://222.184.1.86:8880/queryService/1.0/hts/queryRstation?param_key="
+ param_key + "&secret_key=" + secret_key
+ "&sale_count=3208000993005");
Representation representation = client.get();
InputStream is = representation.getStream();
resultBuffer.append(InputStreamTOString(is));
} catch (Exception e) {
e.printStackTrace();
}
return resultBuffer.toString();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/json");
response.setCharacterEncoding("UTF-8");
String meraccount = request.getParameter("meraccount");
String sale_count = request.getParameter("sale_count");
PrintWriter out = response.getWriter();
String jieguo =doGet(meraccount, sale_count);
out.print(jieguo);
System.out.println(jieguo);
}
这个是前台获取的
var shanghu = $("#CardNo").val();
var shoupiao = $("#PageNum").val();
var data = {
"meraccount":shanghu,
"sale_count": shoupiao,
}
var url ="servlet/BusServlet";//servlet路径
$.post(url,data,function(bbb){
var hhh = bbb;
for(var o in hhh.result){
alert(hhh.result[o].dep_station_name);
}
},"json");
再三检查过了 URL地址没有问题
...全文
相关推荐
xhr-api-example:一个示例前端,它使用 xhr 请求来测试基于 Node 的 RESTful API 的端点
xhr-api-example 一个示例前端,它使用 xhr 请求来测试基于 Node 的 RESTful API 的端点。 有关更多信息,请参阅此 repo: 。
JavaScript XHR详解[项目代码]
本文深入探讨了JavaScript中的XMLHttpRequest(XHR)对象,详细介绍了XHR的基本用法、状态监听、同步与异步请求、HTTP状态码处理以及GET/POST请求的不同数据格式(如JSON、FormData、URL编码)。此外,文章还展示了如何封装一个通用的AJAX函数,并进一步使用Promise进行优化。最后,简要介绍了Fetch API的基本用法及其与XHR的对比。通过丰富的代码示例,帮助读者全面理解XHR和Fetch在JavaScript网络请求中的应用。
nodejs发送http请求时遇到404长时间未响应的解决方法.docx
nodejs发送http请求时遇到404长时间未响应的解决方法.docx
深入理解ajax系列第一篇之XHR对象
ajax是asynchronous javascript and XML的简写,中文翻译是异步的javascript和XML,这一技术能够向服务器请求额外的数据而无须卸载页面,会带来更好的用户体验
asp如何远程获取网页内容
asp技术 如何远程获取网页内容方便获得网站信息



