如何使用jQuery将recaptcha的值发送到另一个页面?
string finalSelectedValue = specificPair(testDictionary,memberId);
JS:
<head>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
...
<form>
<div class="g-recaptcha" data-size="normal" data-sitekey="xxxxxxxxxxxx"></div>
<input type="sumbit" />
</form>
我也试试:
$.post('index.php', {
hiddenRecaptcha: grecaptcha.getResponse(),
...
答案 0 :(得分:0)
从official reference读取;有三种方法,但是你在这里用javascript发送,所以在你的表单中进行以下更改
PS:记住脚本顺序,否则你将无法获得recaptcha
为您的recaptcha div
分配一个唯一的IDif (newRows.Count > 0)
{
//Increment through our array list and build a 2D string array from that list (.Range.Value doesnt like ArrayList objects, so we must use a raw 2D array)...
string[] rowSample = (string[])newRows[0];
string[,] newRowsArray = new string[newRows.Count, rowSample.Length];
int currentRowIndex = 0;
foreach (string[] row in newRows)
{
int columnIndex = 0;
foreach (string columnText in row)
{
newRowsArray[currentRowIndex, columnIndex] = columnText;
columnIndex++;
}
currentRowIndex++;
}
//Hold processing while the current excel file is open, once it closes we can continue...
HoldWhileFileIsOpen(currentExcelFile);
try
{
//Open excel and open current workbook...
Microsoft.Office.Interop.Excel.Application excelApplication = new Microsoft.Office.Interop.Excel.Application();
excelApplication.DisplayAlerts = false;
excelApplication.Visible = false;
Microsoft.Office.Interop.Excel.Workbooks excelWorkbooks = excelApplication.Workbooks;
Microsoft.Office.Interop.Excel.Workbook currentWorkbook = excelWorkbooks.Open(currentExcelFile, Type.Missing, false, Type.Missing, Type.Missing, Type.Missing, true, Type.Missing, Type.Missing, Type.Missing, false, Type.Missing, false, Type.Missing, Type.Missing);
//Open up/Select our current worksheet
Microsoft.Office.Interop.Excel.Sheets workSheets = currentWorkbook.Sheets;
Microsoft.Office.Interop.Excel.Worksheet currentWorkSheet = workSheets[currentWorkSheetName];
currentWorkSheet.Select();
//Create new range, set range number formatting = "@" (text) to retain leading zeroes and other tricky bits in our output, then drop values into range...
Microsoft.Office.Interop.Excel.Range newExcelRows = (Microsoft.Office.Interop.Excel.Range)currentWorkSheet.get_Range(GetColumnAddress(startingColInt) + startingRow, GetColumnAddress(startingColInt + rowSample.Length - 1) + (startingRowIncrementing - 1));
newExcelRows.NumberFormat = "@";
//newExcelRow.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
newExcelRows.Value = newRowsArray;
//Save workbook changes...
currentWorkbook.SaveAs(currentExcelFile, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//Close things up, all COM objects references above must be released and scrubbed thouroughly...
System.Runtime.InteropServices.Marshal.ReleaseComObject(newExcelRows);
newExcelRows = null;
excelApplication.ActiveWorkbook.Close(Type.Missing, Type.Missing, Type.Missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(currentWorkSheet);
currentWorkSheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(workSheets);
workSheets = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(currentWorkbook);
currentWorkbook = null;
//Quit excel...
excelWorkbooks.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbooks);
excelWorkbooks = null;
excelApplication.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApplication);
excelApplication = null;
}
catch (Exception ex)
{
if (ex.Message == "Cannot save as that name. Document was opened as read-only.")
{
}
}
//Hold processing while the current excel file is open, once it closes we can continue...
HoldWhileFileIsOpen(currentExcelFile);
LblStatus.AppendText(" - Done modifying and saving worksheet " + currentWorkSheetName + " (" + currentCountry + ")." + Environment.NewLine);
}
else
{
LblStatus.AppendText(" - No data found for current worksheet " + currentWorkSheetName + " (" + currentCountry + ")." + Environment.NewLine);
}
现在
<div class="g-recaptcha" id="my-recaptcha" data-size="normal"></div>
in
<script type="text/javascript">
var my_recaptcha_widget;
var onloadCallback = function() {
if($('#my-recaptcha').length) {
my_recaptcha_widget = grecaptcha.render('my-recaptcha', {
'sitekey' : '6LfbhhQTAAXXXXXXXXXXXXXCJlFajw'
});
}
};
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>