简体   繁体   English

URL参数和AJAX问题

[英]URL Parameters and AJAX Problem

I have a JSP page that when loaded calls a JavaScript function (loadData()), this function uses an AJAX request to retrieve data from a servlet and return the necessary HTML content to the page. I have a JSP page that when loaded calls a JavaScript function (loadData()), this function uses an AJAX request to retrieve data from a servlet and return the necessary HTML content to the page.

I want to call this url from a button and pass a URL Parameter (....jsp?name=joe), I can do this, but when I try to retrieve it from the servlet I can only see the parameters passed in the AJAX Request, not the parameter in the URL...我想从一个按钮调用这个 url 并传递一个 URL 参数(....jsp?我只能看到从它传递的参数, AJAX 请求,不是URL中的参数...

Is there a reason this is happening?发生这种情况有原因吗? Should I go about this a different way?我应该以不同的方式 go 吗?

Thank you!谢谢!

It sounds like as if the Ajax request is actually a HTTP POST request.听起来好像 Ajax 请求实际上是 HTTP POST 请求。 This way the GET query string in URL will indeed not be parsed.这样 URL 中的 GET 查询字符串确实不会被解析。 You need to parse it yourself in the doPost() method of the servlet.您需要在 servlet 的doPost()方法中自己解析它。 It's available by HttpServletRequest#getQueryString() .它可以通过HttpServletRequest#getQueryString()获得。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM