Application\Home\Conf\tags.php
<?php
return array(
/* 多语言支持 */
'app_begin' => array('Behavior\CheckLangBehavior'),
);Application\Home\Conf\config.php<?php
return array(
'LANG_SWITCH_ON' => true, // 开启语言包功能
'LANG_AUTO_DETECT' => true, // 自动侦测语言 开启多语言功能后有效
'LANG_LIST' => 'zh-cn', // 允许切换的语言列表 用逗号分隔
'VAR_LANGUAGE' => 'l', // 默认语言切换变量
/* URL配置 */
'URL_CASE_INSENSITIVE' => true, //默认false 表示URL区分大小写 true则表示不区分大小写
'URL_MODEL' => 0, //URL模式
'SHOW_PAGE_TRACE' => true, // Trace 信息
);Application\Home\Controller\IndexController.class.php<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index($username = null, $password = null, $verify = null){
if (IS_POST) {
//数据库中数据比对,此处简写
if ($username == 'test' && $password == '123') {
//TODO:跳转到登录前页面
$this->success('login success', U('Index/login_success'));
} else {
$this->error('login error');
}
} else {
$this->display();
}
}
public function login_success(){
echo 'login success';
}
}Application\Home\View\Index\index.html<!-- BEGIN LOGIN FORM -->
<form class="login-form" method="post">
<h3 class="form-title">{$Think.lang.heading_title}</h3>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Username:</label>
<div class="input-icon">
<i class="fa fa-user"></i>
<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Username:" name="username"/>
</div>
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Password:</label>
<div class="input-icon">
<i class="fa fa-lock"></i>
<input class="form-control placeholder-no-fix" type="password" autocomplete="off" placeholder="Password:" name="password"/>
</div>
</div>
<div class="form-actions">
<button type="button" name="button" class="btn green pull-right"> Login </button>
</div>
</form>
<!-- END LOGIN FORM -->
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript"><!--
$(document).ready(function(){
$('button[name=\'button\']').bind('click', function() {
$.ajax({
url: '{:U("Index/index")}',
type : 'post',
dataType: 'json',
data : $(".login-form").serialize(),
beforeSend: function() {
$('button[name=\'button\']').after('<span class="wait">Loading...</span>');
},
complete: function() {
$('.wait').remove();
},
success: function(json) {
if(json.status){
window.location.href = json.url;
};
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
});
//--></script> 为什么关闭多语言,可以正常,开启 报错 SyntaxError: JSON.parse: unexpected character
还有我拿onethink代码测试,开启多语言支持,ajax确实有点问题,验证码都用不了,关闭多语言,正常,求解
最佳答案