验证中...
Languages: Python
Categories: 编程语言基础
Latest update 2019-11-09 00:08
ajax 跨域 flask
Raw Copy
function formSubmit() {
let city = $('cities-select').value
let userTel = $('userTel').value
let userName = $('userName').value
if (window.XMLHttpRequest) { // Mozilla, Safari, IE7+ ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 6 and older
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
// let url = "http://192.168.1.5:7001/api/OperateApi/SaveUserInfo"
httpRequest.open('POST', 'http://127.0.0.1:5000');
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
httpRequest.onreadystatechange = complete;
httpRequest.send();
}
function complete() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
// alert(httpRequest.responseText);
hidden('bg2')
hidden('test')
hidden('share')
show('discount')
show('bg1')
} else {
alert('There was a problem with the request.');
}
}
}
python flask
Raw Copy
from flask import Flask, request
from flask_cors import *
app = Flask(__name__)
CORS(app, supports_credentials=True)
@app.route('/', methods=['GET', 'POST'])
def hello_world():
# 执行index.html中的回调方法, 返回数组 [data1, data2]
print(f'args: {request.args.get("x")}')
return '["壹贰叁","肆伍陆"]' # jsonp函数名
if __name__ == "__main__":
app.run()

Comment list( 0 )

Sign in for post a comment

Help Search