我的网络应用程序中有javascript,我需要检查条件。 JS:
var getholiday="A";
var getHolidaysBydate = function (dates, id, did) {
$.ajax({
type: 'GET',
url: "checkroll/getDate.htm",
data: {
tag: "tagged",
dates: dates,
id: id,
did: did
},
success: function (flag) {
flag = eval(flag);
// var textbox = document.getElementById('get_holiday');
// $.each(holidaysRelatedData.holidayMap,function(kk,v){
// $("#division").append("<option value="+kk+">"+v+"</option>");
// textbox.value = flag;
getholiday = flag;
// })
},
async: false
});
}
$("#add-record").live("click", function () {
var e = document.getElementById("empnum");
var selectEmpID = e.options[e.selectedIndex].value;
var es = document.getElementById("division");
var selectDivID = es.options[es.selectedIndex].value;
getHolidaysBydate(jQuery.trim($("#datepicker").val()), selectEmpID, selectDivID);
if ($(getholiday == "A") {
bottomBar("Holiday for worker.", 'topbarred');
}
}
getHolidaysBydate在servlet GET方法中映射。工作正常
GET:
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String date=null;
int empid=0;
int divid=0;
String flag="B";
Model checkRollModel = new Model();
if (request.getParameter("dates")!= "" && request.getParameter("id")!= ""){
date=request.getParameter("dates");
empid=Integer.parseInt(request.getParameter("id"));
divid=Integer.parseInt(request.getParameter("did"));
}
int val=checkRollModel.getHolidays(date,empid,divid);
if(val>0)
{
flag="A";
}
response.setContentType("application/json");
response.getWriter().write(new Gson().toJson(flag));
}
如果条件匹配,必须进入IF条件,它没有去? 代码有什么问题?
答案 0 :(得分:0)
从你的if条件中取出“$(”。检查firebug控制台。你会在这一行收到语法错误。
答案 1 :(得分:0)
使用boolean解决问题。 var getholiday = true; if(getholiday){}
但我不知道为什么它不与Strings合作。不熟悉JS。