get
fetch(`//xxx.cn/statp/`,{method:'get',mode:'cors'}).then(res =>res.json())
.then(jsn =>{
console.log('Success:', jsn)
}).catch(error => console.error('Error:', error));
post form
let postData = {a:'b'};
fetch('http://data.xxx.com/Admin/Login/login', {
method: 'POST',
mode: 'cors',
credentials: 'include',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: JSON.stringify(postData)
}).then(function(response) {
console.log(response);
});
post json
fetch(`//xxx.cn/statp/`,{method:'post',mode:'cors'
,headers:{'Content-Type': 'application/json'}
,body:JSON.stringify({
'id':'XXX'
})
).then(res =>res.json())
.then(jsn =>{
console.log('Success:', jsn)
}).catch(error => console.error('Error:', error));