<!DOCTYPE html> <html> <head> <title>我是標題</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta content="telephone=no" name="format-detection"> </head> <body> <script src="/Public/js/jquery.min.js"></script> <script src="/Public/js/layer/layer.js"></script> <script type="text/javascript"> $(function(){ // 用一個動畫 來延遲用戶耐心 layer.open({ type: 2 // ,shade: false ,time: 5 }); var url=location.href; $.ajax({ url:"你的url", //請求的URL timeout:5000, //超時時間設置,單位毫秒 type :'get', //請求方式,get或post data :{"url":url}, //請求所傳參數,json格式 dataType:'json',//返回的數據格式 success:function(res){ //請求成功的回調函數 if(res.info=="ok") { layer.open({ content: '成功返回了,我被彈出來', time:3 }); }else { //稍后嘗試 layer.open({ content: '獲取數據失敗了,我被彈出來' }); } }, complete : function(XMLHttpRequest,status){ //請求完成后最終執行參數 if(status=='timeout') { //超時,status還有success,error等值的情況 layer.open({ content: '請求超時,請刷新重試', btn: ['OK'] }); } } }); }) </script> </body> </html>