验证码刷新(mewebstudio)
Captcha refresh (mewebstudio)
目的:刷新验证码图片。
routes.php
Route::get('/get_captcha/{config?}', function (\Mews\Captcha\Captcha $captcha, $config = 'default') {
return $captcha->src($config);
});
验证码图片 (mypage.blade.php):
<img src="{{ Captcha::img() }}" alt="captcha" class="captcha-img" data-refresh-config="default">
js文件:
$(document).ready(function(){
$('img.captcha-img').on('click', function () {
var captcha = $(this);
var config = captcha.data('refresh-config');
//console.log(config);
$.ajax({
method: 'GET',
url: '/get_captcha/' + config,
}).done(function (response) {
captcha.prop('src', response);
});
});
});
问题: 我的控制台上的 js ajax 错误:http://localhost/get_captcha/default 404
错误。
参考:https://github.com/mewebstudio/captcha/issues/54#issuecomment-141483501
其他信息: 我正在为 Laravel 4 使用验证码,但我无法在行中找到名为 src
的方法以上 $captcha->src($config)
提前致谢。
重要说明:将 captcha_img('flat') 更改为 laavel4 语法。两者的逻辑相同。
验证码HTML-
<div class="form-group refereshrecapcha">
{!! captcha_img('flat') !!}
</div>
<input id="captcha" class="form-control" type="text" name="captcha" data-validation="required" >
<a href="javascript:void(0)" onclick="refreshCaptcha()">Refresh</a>
在重新生成验证码的控制器内创建一个函数。
控制器代码-
public function refereshCapcha(){
return captcha_img('flat');
}
验证验证码请求-
'captcha' => 'required|captcha',
将您的函数标记到可以使用ajax 调用的路由文件中。
路由文件-
Route::get('/refereshcapcha', 'HelperController@refereshCapcha');
创建函数以发出 ajax 请求
AJAX-
<script>
function refreshCaptcha(){
$.ajax({
url: "/refereshcapcha",
type: 'get',
dataType: 'html',
success: function(json) {
$('.refereshrecapcha').html(json);
},
error: function(data) {
alert('Try Again.');
}
});
}
</script>
目的:刷新验证码图片。
routes.php
Route::get('/get_captcha/{config?}', function (\Mews\Captcha\Captcha $captcha, $config = 'default') {
return $captcha->src($config);
});
验证码图片 (mypage.blade.php):
<img src="{{ Captcha::img() }}" alt="captcha" class="captcha-img" data-refresh-config="default">
js文件:
$(document).ready(function(){
$('img.captcha-img').on('click', function () {
var captcha = $(this);
var config = captcha.data('refresh-config');
//console.log(config);
$.ajax({
method: 'GET',
url: '/get_captcha/' + config,
}).done(function (response) {
captcha.prop('src', response);
});
});
});
问题: 我的控制台上的 js ajax 错误:http://localhost/get_captcha/default 404
错误。
参考:https://github.com/mewebstudio/captcha/issues/54#issuecomment-141483501
其他信息: 我正在为 Laravel 4 使用验证码,但我无法在行中找到名为 src
的方法以上 $captcha->src($config)
提前致谢。
重要说明:将 captcha_img('flat') 更改为 laavel4 语法。两者的逻辑相同。
验证码HTML-
<div class="form-group refereshrecapcha">
{!! captcha_img('flat') !!}
</div>
<input id="captcha" class="form-control" type="text" name="captcha" data-validation="required" >
<a href="javascript:void(0)" onclick="refreshCaptcha()">Refresh</a>
在重新生成验证码的控制器内创建一个函数。
控制器代码-
public function refereshCapcha(){
return captcha_img('flat');
}
验证验证码请求-
'captcha' => 'required|captcha',
将您的函数标记到可以使用ajax 调用的路由文件中。
路由文件-
Route::get('/refereshcapcha', 'HelperController@refereshCapcha');
创建函数以发出 ajax 请求
AJAX-
<script>
function refreshCaptcha(){
$.ajax({
url: "/refereshcapcha",
type: 'get',
dataType: 'html',
success: function(json) {
$('.refereshrecapcha').html(json);
},
error: function(data) {
alert('Try Again.');
}
});
}
</script>