瀏覽器跨域測(cè)試

一:前端瀏覽器禁用安全設(shè)置

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比乳山網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式乳山網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋乳山地區(qū)。費(fèi)用合理售后完善,10余年實(shí)體公司更值得信賴。

chrome的話可以通過在命令行,輸入chrome.exe --allow-file-access-from-files --user-data-dir="C:/Chrome dev session" --disable-web-security

二:http服務(wù)器設(shè)置:

   nginx的設(shè)置:

location /api {

 add_header Access-Control-Allow-Origin $http_origin;

# add_header Access-Control-Allow-Origin *;

add_header Access-Control-Allow-Credentials true;

 add_header Access-Control-Allow-Methods *;

 add_header Access-Control-Allow-Headers $http_access_control_request_headers;

 add_header Access-Control-Max-Age 3600;

     proxy_set_header Host $host;

     proxy_set_header X-Real-IP $remote_addr;

     proxy_set_header REMOTE-HOST $remote_addr;

     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

     proxy_pass http://masConsole;

     if ($request_method = OPTIONS){

         return 200; 

     }

 }

例子:編寫html跨域的ajax頁(yè)面:

<html>  

  

<head>  

    <title>tab標(biāo)簽頁(yè)</title>  

    <style>  

        * {  

            padding: 0;  

            margin: 0;  

        }  

        ul {  

            list-style-type: none;  

        }  

        body {  

            margin: 50px;  

        }  

        #ul {  

            height: 30px;  

            margin-bottom: 10px;  

        }  

        #ul li {  

            height: 30px;  

            line-height: 30px;  

            padding: 0 15px;  

            border: 1px solid #abcdef;  

            float: left;  

            margin-right: 3px;  

            cursor: pointer;  

        }  

        #ul li.current {  

            background: #abcdef;  

        }  

        #content div {  

            width: 300px;  

            height: 200px;  

            border: 1px solid #abcdef;  

            display: none;  

        }  

        #content div.show {  

            display: block;  

        }  

    </style>  

    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>  

    <script>  

        $(function () {  

            $("#ul li").click(function () {  

                /*//1.點(diǎn)擊li的時(shí)候切換樣式  

                $(this).addClass("current").siblings().removeClass("current");  

                //2.根據(jù)li的索引值,來(lái)確定哪個(gè)div顯示,其他div隱藏  

                $("#content>div").eq($(this).index()).show().siblings().hide();*/  

                //$(this).addClass("current").siblings().removeClass("current").parent().next().children().eq($(this).index()).show().siblings().hide();  

                $(this).addClass("current").siblings().removeClass("current").parent().next().find("div").eq($(this).index()).show().siblings().hide();  

            

   $.ajax({

url: 'https://mp.sda.cn:9999/api/customer/uaa/nologin/login?Session_businessId=1',

type: 'post',

data:{"nameLogin":"000044","passwordLogin":"000000"},

dataType: 'json',

success: function(data){

   alert(JSON.stringify(data));

console.log(JSON.stringify(data));

},

error: function(err){

 alert(JSON.stringify(err));

console.log(JSON.stringify(err));

}

});

});  

        });  

    </script>  

</head>  

  

<body>  

    <ul id="ul">  

        <li class="current">php</li>  

        <li>ruby</li>  

        <li>python</li>  

    </ul>  

    <div id="content">  

        <div class="show">php...介紹</div>  

        <div>ruby...介紹</div>  

        <div>python...介紹</div>  

chrome的話可以通過在命令行,輸入chrome.exe --allow-file-access-from-files --user-data-dir="C:/Chrome dev session" --disable-web-security

    </div>  

</body>  

  

</html> 

文章題目:瀏覽器跨域測(cè)試
轉(zhuǎn)載來(lái)源:http://bm7419.com/article22/jdigjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)企業(yè)網(wǎng)站制作、網(wǎng)站導(dǎo)航手機(jī)網(wǎng)站建設(shè)、網(wǎng)站收錄

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司