function myFetch(url, data) {
return new Promise((resolve, reject) => {
fetch(url, {
method: "POST",
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
},
body: formator(data)
})
}).then((res) => {
return res.json();
}).then((data) => {
resolve(data);
}, (error) => {
reject(error);
})
}
function formator(data) {
var str = "";
Object.keys(data).map(key => {
str += key + "=" + data[key] + "&";
})
if (str) {
return str.substr(0, str.lastIndexOf('&'));
}
}
// "user_id=iwen@qq.com&password=iwen123&verification_code = crfvw "
myFetch("http://iwenwiki.com/api/blueberrypai/login.php", {
user_id: "iwen@qq.com",
password: "iwen123",
verification_code: "crfvw"
}).then((data) => {
console.log(data);
}).catch((error) => {
console.log(error);
})
老师为什么我打印不出来