Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 验证码刷新(mewebstudio)_Php_Jquery_Ajax_Laravel 4_Captcha - Fatal编程技术网

Php 验证码刷新(mewebstudio)

Php 验证码刷新(mewebstudio),php,jquery,ajax,laravel-4,captcha,Php,Jquery,Ajax,Laravel 4,Captcha,目的:刷新验证码图像 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="ca

目的:刷新验证码图像

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">
$(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
错误

参考:

其他信息:我正在使用Laravel 4的验证码,在上面的
$captcha->src($config)
行中找不到名为
src
的方法


提前感谢。

重要提示:将captcha\u img(“平面”)更改为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',
Route::get('/refereshcapcha', 'HelperController@refereshCapcha');
<script>
function refreshCaptcha(){
$.ajax({
url: "/refereshcapcha",
type: 'get',
  dataType: 'html',        
  success: function(json) {
    $('.refereshrecapcha').html(json);
  },
  error: function(data) {
    alert('Try Again.');
  }
});
}
</script>
验证验证码请求-

<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',
Route::get('/refereshcapcha', 'HelperController@refereshCapcha');
<script>
function refreshCaptcha(){
$.ajax({
url: "/refereshcapcha",
type: 'get',
  dataType: 'html',        
  success: function(json) {
    $('.refereshrecapcha').html(json);
  },
  error: function(data) {
    alert('Try Again.');
  }
});
}
</script>
将函数标记到可以使用ajax调用的路由文件中

路由文件-

<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',
Route::get('/refereshcapcha', 'HelperController@refereshCapcha');
<script>
function refreshCaptcha(){
$.ajax({
url: "/refereshcapcha",
type: 'get',
  dataType: 'html',        
  success: function(json) {
    $('.refereshrecapcha').html(json);
  },
  error: function(data) {
    alert('Try Again.');
  }
});
}
</script>
创建用于发出ajax请求的函数

AJAX-

<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',
Route::get('/refereshcapcha', 'HelperController@refereshCapcha');
<script>
function refreshCaptcha(){
$.ajax({
url: "/refereshcapcha",
type: 'get',
  dataType: 'html',        
  success: function(json) {
    $('.refereshrecapcha').html(json);
  },
  error: function(data) {
    alert('Try Again.');
  }
});
}
</script>

函数refreshCaptcha(){
$.ajax({
url:“/refereshcapcha”,
键入:“get”,
数据类型:“html”,
成功:函数(json){
$('.refereshreapcha').html(json);
},
错误:函数(数据){
警惕(“再试一次”);
}
});
}