C # Cross-origin submission form using jsonp

Source: Internet
Author: User

C # Cross-origin submission form using jsonp

Submit a message across domains and return whether the message is successful!


C # Server:

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 = "not retrieved IP";} string strSql = ""; HSBY_DBEntities db = new HSBY_DBEntities (); // verify whether too many 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
 
  
(StrSql). FirstOrDefault (); if (ipCount> 10) {str + = "([{\" do not submit again! \ "}]);"; 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:

// Return the data processing function displayResult (data) {var iRusltstr = data [0]. rusltstr; if (iRusltstr = "OK") {// close the mask $ ("# submitmask "). fadeOut (500); alert ("submitted successfully! ");} Else {$ (" # submitmask "). fadeOut (500); alert (iRusltstr +" please contact us by other means! ");}}

// Submit the message function SubmitMsg () {var AllInput =$ ("# formwrap input"); var iTextarea =$ ("# formwrap textarea"); // obtain 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", "") ;}// missing focus verification AllInput. blur (function () {FormValiudat ($ (this) ;}); // form verification method function FormValiudat ($ input) {var promptStr = ""; var pattern = new RegExp ("[~ '! # $ % ^ & * ()-+ _ =] "); If (pattern. test ($ input. val () {alert (" invalid character! Please do not try to inject it! "); 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": // emailvar reg =/^ [a-z0-9] + ([. _ \-] * [a-z0-9]) * @ ([a-z0-9] + [-a-z0-9] * [a-z0-9] + .) {} [a-z0-9] + $/; if (! Reg. test ($ input. val () {$ ("# redpoint_email "). removeClass ("hide"); $ input. focus (); return false;} else {$ ("# redpoint_email "). addClass ("hide");} break; case "tel": // call 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 words! "); Return false;} break;} return true;} // form submission $ (" # 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 ;}}// open the 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 );})}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.