简体   繁体   English

Javascript未在JSP转发操作上执行

[英]Javascript not executing on JSP forward action

Hi I have one jsp page and I have to update two html select boxes with the data of an inf file. 嗨,我有一个jsp页面,我必须用一个inf文件的数据更新两个html选择框。 On selecting the first combo(initially also not loading the second combo), the second will have to change accordingly. 在选择第一个组合时(最初也不会加载第二个组合),第二个将必须进行相应的更改。 Since java script variable is not accessible from java, I had sent the value of first combo to an another jsp by ajax. 由于无法从Java访问Java脚本变量,因此我已经用Ajax将first combo的值发送给了另一个jsp。 And then return it to first jsp itself.Plaese help me. 然后将其返回给第一个jsp本身。Plaese帮助我。

Maybe I'm getting it wrong but looking at your code it seems that you are doing AJAX request on selectbox change event, but you are not doing anything with the response. 也许我弄错了,但查看您的代码,似乎您正在对selectbox change事件执行AJAX请求,但对响应没有任何处理。 So basically what happens is you are doing an initial render to your jsp and everything is fine. 所以基本上发生的是您正在对jsp进行初始渲染,一切都很好。 Now you are changing selectbox option and AJAX request is sent to dummy.jsp. 现在,您正在更改selectbox选项,并且AJAX请求已发送到dummy.jsp。 dummy.jsp is receiving it and redirecting the maker of the request to User.jsp. dummy.jsp正在接收它,并将请求的生成者重定向到User.jsp。 User.jsp-s content is sent back but nothing is done on the client side AJAX call with this response. User.jsp的内容被发回,但是在客户端AJAX调用中,对此响应没有任何反应。

What you should do is have your logic at dummy.jsp(or even better at some servlet) which based on your AJAX call request parameters returns for example a JSON with data that you can process in jQuery.ajax success event. 您应该做的是使您的逻辑位于dummy.jsp(甚至更好的是某些servlet)上,该逻辑基于您的AJAX调用请求参数返回,例如,包含可在jQuery.ajax成功事件中处理的数据的JSON。 In there you can use this JSON to readjust your selectboxes and other data with javascript. 在这里,您可以使用此JSON通过javascript重新调整选择框和其他数据。 Check the examples at the end of jQuery.ajax manual: http://api.jquery.com/jquery.ajax/ 检查jQuery.ajax手册末尾的示例: http : //api.jquery.com/jquery.ajax/

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

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