我想从中获取对象json
这是我到目前为止所做的success
ajax
我的下拉列表
<select id="testers_team" class="tester_team">
<optgroup label="Current Value">
<option><c:out value="${info.team}"></c:out></option>
</optgroup>
<optgroup label="Teams">
<c:forEach var="team" items="${requestScope.testers}">
<option value="${team.key}">${team.key}</option>
</c:forEach>
</optgroup>
</select>
这是我Ajax
的,select
上面是通过循环迭代的,所以我必须使用每个来知道我正在使用哪个下拉列表(只是为了通知你们)
$('.tester_team').each(function(){
$(this).change(function() {
$.ajax({
url: 'Analysis',
type: 'POST',
dataType: 'json',
data: {team: $(this).val()},
success: function(data){
alert(data); // alert not working
}
});
});
});
我Gson
在我的 servlet 上使用以下代码:
String team = request.getParameter( "team" );
HashMap<String, ArrayList<String>> testerList
= new UsersDAO().getTestersOfAllTeams();
ArrayList<String> testers = testerList.get( team );
if( testers != null )
{
response.setContentType( "application/json" );
response.setCharacterEncoding( "UTF-8" );
try
{
response.getWriter().write( new Gson().toJson( testers ) );
//this one is printing so that means it actually succeed to parse?
System.out.println( team );
}
catch( IOException e )
{
// just want to test out if it really failed
System.out.println( "failed" );
log.debug( "Unable to get parse request", e );
}
}
问题出在脚本中,当我更改下拉列表时Ajax
不会触发函数我的代码有什么问题?alert(data);
还是我滥用了代码?