我正在尝试调用操作servlet createLabel.do,但看起来像不在调用操作类。我用萤火虫调试,它看起来像这个网址被称为,但接收没有反应。
这里的javascript函数:对Struts操作的Ajax调用不会返回响应
<script type="text/javascript" charset="utf-8">
$(function() {
$("#createLabel").click(function() {
$.ajax({
type: "POST",
url: "/createLabel.do",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: { lab_no: $("#labNum").val(),accNum: $("#accNum").val(), label: $("#label").val() },
success: function() {
alert("success");
}
});
});
});
</script>
这里是我的动作类:
public class CreateLabelAction extends Action{
public ActionForward execute (ActionMapping mapping, HttpServletRequest request, HttpServletResponse response){
String label = request.getParameter("label");
String lab_no = request.getParameter("lab_no");
String accNum = request.getParameter("accNum");
response.setContentType("application/json");
try {
DB db = new DB(DB.DATA);
Connection conn = db.GetConnection();
String insertstmt = "update Info set label='"+label+"' where lab_no="+lab_no+" and accNum='"+accNum+"'";
logger.info(insertstmt);
PreparedStatement pstmt = conn.prepareStatement(insertstmt);
pstmt.executeUpdate();
pstmt.close();
db.closeConn();
logger.info("Label created successfully.");
} catch (Exception e){
logger.error("Error inserting label into Info" + e);
request.setAttribute("error", "There was an error creating a label.");
}
logger.info("Label ="+label);
label = StringEscapeUtils.escapeJavaScript(label);
return mapping.findForward("complete");
}
}
这里是在struts-config.xml配置:
<action input="/labDi.jsp" name="LabelForm" path="/createLabel" scope="request" type="all.pageUtil.CreateLabelAction">
<forward name="complete" path="/labDi.jsp" />
</action>
是否有人可以告诉我为什么行动班没有被唤起?提前致谢。
什么类型的DOM元素是'#createLabel'?提交按钮,链接,标准按钮,div,...? –
标准按钮: – Sapphire
此按钮是否在表单中?当你点击按钮时,你在FireBug中看到了什么?是否发送了AJAX请求? –