标签:des style http color io os 使用 java ar
跨域提交留言,并返回是否成功!
C#服务端:
public void FeedBackPost(string name, string email, string tel, string website, string desc, string thisIp, string sourse, string callBack) { try { Response.ContentType = "application/x-javascript"; string str = callBack; if (thisIp==null) { thisIp = "未取到IP"; } string strSql = ""; HSBY_DBEntities db = new HSBY_DBEntities(); //验证ip短时间内是否提交太多 Regex rx = new Regex(@"((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))"); if (rx.IsMatch(thisIp)) { strSql = @"select count(*) from fb_srv_main where ip='" + thisIp + "'"; int ipCount = db.ExecuteStoreQuery<int>(strSql).FirstOrDefault(); if (ipCount>10) { str += "([{\"请勿重复提交!\"}]);"; Response.Write(str); return; } } fb_srv_main newItem = new fb_srv_main(); newItem.name = name; newItem.email = email; newItem.tel = tel; newItem.site = website; newItem.content_str = desc; newItem.ip = thisIp; newItem.creat_by = sourse; newItem.creat_on = DateTime.Now; _mainBLL.Create(ref validationErrors, newItem); //HttpContext context = new HttpContext(); if (validationErrors.Count>0) { str+=validationErrors[0].ErrorMessage; Response.Write(str); return; } FeedBackEmail( name, email, tel, website, desc, thisIp, sourse); str += "([{\"Rusltstr\":\"OK\"}]);"; Response.Write(str); return; } catch (Exception ex) { Response.ContentType = "application/x-javascript"; Response.Write(callBack + "([{\"Rusltstr\":\"出错了!\"}]);"); return; } }
//提交留言返回数据处理 function displayResult(data) { var iRusltstr=data[0].Rusltstr; if(iRusltstr=="OK"){ //关闭遮罩 $("#submitmask").fadeOut(500); alert("提交成功!"); }else{ $("#submitmask").fadeOut(500); alert(iRusltstr+" 请使用其他方式联系我们!"); } }
//提交留言 function SubmitMsg(){ var AllInput=$("#formwrap input"); var iTextarea=$("#formwrap textarea"); //获得焦点样式 AllInput.focus(function(){AddFocusStyle($(this))}); AllInput.blur(function(){AddFocusStyle($(this))}); iTextarea.focus(function(){AddFocusStyle($(this))}); iTextarea.blur(function(){AddFocusStyle($(this))}); function AddFocusStyle(iInput){ if(iInput.attr("style")=="" || iInput.attr("style")==null){ iInput.attr("style","border:1px solid #bcbcbc;color:#7a7a7a;"); }else{ iInput.attr("style",""); } } //丢失焦点验证 AllInput.blur(function(){ FormValiudat($(this)); }); //表单验证方法 function FormValiudat($input){ var promptStr=""; var pattern = new RegExp("[~'!#$%^&*()-+_=]"); if(pattern.test($input.val())){ alert("非法字符!亲,请勿尝试注入哦!"); return false; } switch($input.attr("id")) { case "name": //姓 if($input.val().length>10) { $("#redpoint_name").removeClass("hide"); $input.focus(); return false; }else{ $("#redpoint_name").addClass("hide"); } break; case "email": //email var reg = /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/; if (!reg.test($input.val())) { $("#redpoint_email").removeClass("hide"); $input.focus(); return false; }else{ $("#redpoint_email").addClass("hide"); } break; case "tel": //电话 var isMobile=/^(?:13\d|15\d|18\d)\d{5}(\d{3}|\*{3})$/; var isPhone=/^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/; if(!isMobile.test($input.val()) && !isPhone.test($input.val())){ $("#redpoint_tel").removeClass("hide"); $input.focus(); return false; }else{ $("#redpoint_tel").addClass("hide"); } break; case "website": if(!(/[^\d]/g).test($input.val())){ $("#redpoint_website").removeClass("hide"); $input.focus(); return false; }else{ $("#redpoint_website").addClass("hide"); } break; case "desc": var mainText=$input.val(); if(mainText.length>=100){ alert("最多100个字!"); return false; } break; } return true; } //表单提交 $("#formsubmit").click(function(){ var $feedback_input=$("#formleft input"); for(var i=0;i<$feedback_input.length;i++){ var $thisInput=$($feedback_input[i]); if(!FormValiudat($thisInput)) { return; }; } //提交表单前打开遮罩 $("#submitmask").fadeIn(500); var url = "http://www.sparkdesign.cn:8888/MainAjax/FeedBackPost" url = "http://www.sparkdesign.cn:8888/MainAjax/FeedBackPost?name="+$("#name").val()+"&email="+$("#email").val()+"&tel="+$("#tel").val()+"&website="+$("#website").val()+"&desc="+$("#desc").val()+"&thisIp="+$("#keleyivisitorip").html()+"&callback=displayResult" $.getScript(url); }) }
标签:des style http color io os 使用 java ar
原文地址:http://blog.csdn.net/huileiforever/article/details/39322449