我在我的网站上使用codeigniter。现在我正在努力获得验证码。为了刷新验证码图像,我使用Jquery Ajax。当Jquery在控制器中调用我的captcha_refresh函数时,我得到内部服务器错误。 这是我的控制器:
class Register extends CI_Controller {
function __construct(){
parent::__construct();
//start session
session_start();
$this->load->model('model_users');
$this->load->helper('captcha');
}
function index() { ...}
//here goes some code
// For new image on click refresh button.
function captcha_refresh(){
header('Content-type: application/json');
$values = array(
'word' => '',
'word_length' => 8,
'img_path' => './images/images/',
'img_url' => base_url() .'images/images/',
'font_path' => base_url() . 'system/fonts/texb.ttf',
'img_width' => '150',
'img_height' => 50,
'expiration' => 3600
);
$data= create_captcha($values);
$_SESSION['captchaWord'] = $data['word'];
echo json_encode($data);
exit;
}
}
这是我的js函数:
function refresh_captcha() {
new Ajax.Request(baseURL + 'Register/captcha_refresh', {
method: 'get',
evalJSON: true,
parameters: {},
onSuccess: function (transport) {
var answer = JSON.parse(transport.responseText);
},
onError: function () {
alert('Error');
},
onComplete: function () {
}
});
}