通过前端访问后台执行操作,如 $.ajax,$.post,$.get等等所有包含url: "地址" 属性都可以调用该方法,方法如下:
前端通过$.post 进行调用后台操作:
<script>
$(function(){
$.post(
'<?php echo $this->getUrl('index/index/loginValidate'); ?>',
$('#loginFm').serialize(),
function(result){
if(result.error){
$('.messages').html('<p class="error-msg">'+result.msg.join('<br>')+'</p>');
}else{
$('.messages').html('<p class="success-msg">登录成功,请稍候...</p>');
top.location.replace(window.location.href);
}
},
'json'
);
});
</script>
后端php方法
public static function getUrl($path = '', $sep = false)
{
global $_CONFIG;
$path = trim($path, '/');
$url = '';
if ($_CONFIG['HttpPath']) {
$ur