Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Browser cross-domain testing

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

One: front-end browsers disable security settings

For chrome, you can type chrome.exe-- allow-file-access-from-files-- user-data-dir= "C:/Chrome dev session"-- disable-web-security on the command line

Two: http server settings:

Settings for nginx:

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

}

}

Example: write html cross-domain ajax pages:

Tab tab

* {

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

}

$(function () {)

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

/ * / 1. Switch styles when you click li

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

/ / 2. According to the index value of li, determine which div is displayed and the other div is hidden.

$("# 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))

}

});

});

});

Php

Ruby

Python

Php... Introduction

Ruby... Introduction

Python... Introduction

For chrome, you can type chrome.exe-- allow-file-access-from-files-- user-data-dir= "C:/Chrome dev session"-- disable-web-security on the command line

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report