ajax success is not defined,html - reCAPTCHA ajax verification ReferenceError: success is not define...

Well I solved my own problem by sending the post data to the page controller.

JS:

$.ajax({

type: 'GET',

contentType: "application/json",

url: "/Register/veriCAPTCHA",

data: {

privateKey: 'XXXXXXXXXXXXXXXX',

remoteip: document.getElementById("ipaddress").innerHTML,

challenge: Recaptcha.get_challenge(),

response: Recaptcha.get_response()

},

success: function (data) {

if (data == false) {

valiCAPTCHA = false;

ALERT("The CAPTCHA code you entered is invalid. Please try again.");

Recaptcha.reload();

}

else {

valiCAPTCHA = true;

}

}

});

CS controller:

[HttpGet]

public JsonResult veriCAPTCHA(string privateKey, string remoteip, string challenge, string response)

{

string postData = String.Format("privatekey={0}&remoteip={1}&challenge={2}&response={3}",

privateKey, remoteip,

challenge, response);

JsonResult result = new JsonResult();

byte[] postDataBuffer = System.Text.Encoding.ASCII.GetBytes(postData);

Uri serviceUri = new Uri("http://api-verify.recaptcha.net/verify", UriKind.Absolute);

try

{

HttpWebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create(serviceUri);

webRequest.ContentType = "application/x-www-form-urlencoded";

webRequest.ContentLength = postDataBuffer.Length;

webRequest.Method = "POST";

//incase you are using a proxy server

IWebProxy proxy = WebRequest.GetSystemWebProxy();

proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

webRequest.Proxy = proxy;

Stream requestStream = webRequest.GetRequestStream();

requestStream.Write(postDataBuffer, 0, postDataBuffer.Length);

HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

string jsonResponse = string.Empty;

using (StreamReader sr = new StreamReader(webResponse.GetResponseStream()))

jsonResponse = sr.ReadToEnd();

string[] tokens = jsonResponse.Split(new char[] { '\n' });

if (tokens.Length == 2)

{

return Json(false, JsonRequestBehavior.AllowGet);

}

else

{

return Json(false, JsonRequestBehavior.AllowGet);

}

}

catch (Exception ex)

{

return Json(false, JsonRequestBehavior.AllowGet);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值