1.前台代码,定义一个隐藏域
<input type="hidden" id="closeWindow"/>
2.利用Jquery向隐藏域里面存值
function alarmalert(flag) { var data; if(mark==1){ data = {flag:flag,mark:1}; }else{ data = {flag:flag}; } $.ajax({ url:format_url('/message/getAlarmAlert'), type: "get", dataType : "json", async: true, data: data, success:function(result){ if(result) { result = $.parseJSON(result); var data = result.alarmID+","+result.module+","+result.deviceType+","+result.farmName+"," +result.deviceName+","+result.time+","+result.alarmCode; $('#closeWindow').val(data);//将值存到隐藏域中 loadAlarmData(result.farmDesc+" "+result.time+" "+result.deviceDesc+" "+result.descriptionCN, flag); } result = null; }, complete: function(XMLHttpRequest, textStatus) { XMLHttpRequest = null; textStatus = null; }, error: function(XMLHttpRequest, textStatus, errorThrown){ XMLHttpRequest = null; textStatus = null; errorThrown = null; } }); }
3.隐藏域取值
function closeWindow(){ var data = $('#closeWindow').val();//取值 $.ajax({ url:format_url('/message/closeAlarmAlert'),//利用ajax返回后台 type: "get", dataType : "json", async: true, data: {data:data} }); };