首页 > 代码库 > php ajax请求和返回

php ajax请求和返回

        define(‘NOW_TIME‘,      $_SERVER[‘REQUEST_TIME‘]);        define(‘REQUEST_METHOD‘,$_SERVER[‘REQUEST_METHOD‘]);        define(‘IS_GET‘,        REQUEST_METHOD ==‘GET‘ ? true : false);        define(‘IS_POST‘,       REQUEST_METHOD ==‘POST‘ ? true : false);        define(‘IS_PUT‘,        REQUEST_METHOD ==‘PUT‘ ? true : false);        define(‘IS_DELETE‘,     REQUEST_METHOD ==‘DELETE‘ ? true : false);        define(‘IS_AJAX‘,       ((isset($_SERVER[‘HTTP_X_REQUESTED_WITH‘]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH‘]) == ‘xmlhttprequest‘) || !empty($_POST[C(‘VAR_AJAX_SUBMIT‘)]) || !empty($_GET[C(‘VAR_AJAX_SUBMIT‘)])) ? true : false);




 

function ajaxReturn($code, $msg = ‘‘, $data = array(), $redirect = ‘‘) {    $data = array(        ‘code‘ => $code,        ‘message‘ => $msg,        ‘data‘ => $data,        ‘redirect‘ => $redirect    );    header(‘Content-Type:application/json; charset=utf-8‘);    exit(jsonEncode($data));}

 

php ajax请求和返回