根据客户端浏览器首选语言的不同,返回不同的欢迎消息

来源:互联网 发布:手机淘宝网手机淘宝 编辑:程序博客网 时间:2024/06/05 23:43

php:

<?php//header('Content-Type: application/javascript');//根据客户端浏览器首选语言的不同,返回不同的欢迎消息$arr = getallheaders();$lang = $arr['Accept-Language'];if( substr($lang, 0, 2)==='zh'  ){echo 'alert("你好!");';}else{echo 'alert("Hello!")';}?>

html:

<!DOCTYPE html><html> <head>  <title> new document </title>  <meta charset="utf-8" /> </head> <body><button>获取来自服务器的欢迎消息</button> <script src="js/jquery-1.11.3.js"></script><script>$('button').click(function(){//使用$.get()发起AJAX请求/*$.get('5-hello.php',function(data){//console.log(arguments);eval(data);});*/$.getScript('5-hello.php');});</script> </body></html>


0 0
原创粉丝点击