【发布时间】:2015-12-18 20:03:25
【问题描述】:
我正在尝试使用 request.getParameter(); 在我的 jsp 中获取我的 Ajax 调用提交的值;但它一直给null,这是我的$.Ajax
function get(){
var select = document.getElementById("model");
var selectedString = select.options[select.selectedIndex].value;
alert(selectedString);
$.ajax({
type:"POST",
url:"index.jsp",
data:{fram:selectedString},
dataType:"text",
success:function(data){
alert("data loaded: " );
}});
}
这就是触发 get();
<select id="model" class="form-control" name="From"style="background:#FCDFD5;" onchange="get()">
<%
while(r.next()){
%>
<option><%=r.getString(3)%></option>
<% } %></select>
警报有效,但当我尝试打印我的 jsp 中的值时它显示为 null,这是我的 request.getParameter();
<% String name=request.getParameter("fram");
out.println(name);
%>
提前非常感谢
【问题讨论】:
-
alert("data loaded successfully" );怎么能说null? -
selectedString 的值是多少?
-
selectedString 必须在 javascript 中给它一个值。请更新您的帖子,显示您如何设置此变量以及它在 javascript 中的定义位置
-
selectedString 是下拉列表中的选定值
-
除非它被设置为全局变量或与 ajax 调用在同一范围内,否则在您在此处发布的脚本中为 null