我正在尝试将数据ajax传递给servlet。我的html有3个可点击列表项,点击后,我想传递该元素的文本。我没有遇到点击元素并获取它的文本,但我的servlet没有获得值。
我的剧本,
<decision name="CheckFile">
<switch>
<case to="nextOozieTask">
${fs:exists('/path/test_08_01_2016.csv')} <!--do note the path which should be in ''-->
</case>
<default to="MailActionFileMissing" />
</switch>
</decision>
我在servlet中的doGet(),
<script type="text/javascript">
// Example document-ready block
$(function() {
// Your event
$('li').click(function() {
// Get the ID for the element that was clicked
var id = $(this).attr('id');
var f = document.getElementById('clicked');
f.value = id;
//alert(id);
$.ajax({
url : 'GetPhone',
data : {id : id},
type : 'get',
success : function(data) {
//alert(id);
},
error : function() {
alert('error');
}
});
});
});
</script>
最后,重要的部分来自html,
System.out.println("Servlet called!!");
String text = "Update successful";
String name = request.getParameter("clickedFeature");
PrintWriter out = response.getWriter();
out.println(name + " " + text);