Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Browser cross-domain testing

Shulou Source: shulou.com Published: 2022-06-03 06:34:06 09月21日 Update

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

Tags: Through command input browser browse security example front end time server tag style index page switch service test Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MySQL NVidia Shulou Technology Redmi