Submit a message across domains and return to success!
C # Service side:
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 Not Taken"; } String strSQL = ""; Hsby_dbentities db = new hsby_dbentities (); Verify that the IP is committing too many regex rx = new Regex (@ "(?:(?) within a short time. : 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 + = "([{\") do not repeat the submission! \"}]);"; 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\ ": \" Error! \"}]);"); Return } }
JS Client:
Submit a message return data processing function Displayresult (data) { var irusltstr=data[0]. Rusltstr; if (irusltstr== "OK") { //close Mask $ ("#submitmask"). FadeOut ("Submit success!") "); } else{ $ ("#submitmask"). FadeOut, alert (irusltstr+ "please contact us using other means!") "); }
Submit Message Function submitmsg () {var allinput=$ ("#formwrap input"), Var itextarea=$ ("#formwrap textarea");// Gets the focus style 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", "");}} Lost Focus Validation Allinput.blur (function () {Formvaliudat ($ (this));}); /form Validation method function Formvaliudat ($input) {var promptstr= ""; var pattern = new RegExp ("[~ '!#$%^&* ()-+_=]"); if ( Pattern.test ($input. Val ())) {alert ("illegal character! Kiss, don't try to inject Oh! "); return false;} Switch ($input. attr ("id")) {case "name"://Surname if ($input. Val (). length>10) {$ ("#redpoint_name"). Removeclass ("Hide"); $input. focus (); return false;} else{$ ("#redpoint_name"). AddClass ("Hide");} Break;case "Email"://emailvar 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"://Phone 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 ("Up to 100 characters!") "); return false;} break;} return true;} The form submits $ ("#formsubmit"). Click (function () {var $feedback _input=$ ("#formleft input"), and for (Var i=0;i< $feedback _ input.length;i++) {var $thisInput =$ ($feedback _input[i]); Formvaliudat ($thisInput){return;};} Open Mask $ ("#submitmask") before submitting the form. 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); })}
C # using JSONP for cross-domain submission forms