【发布时间】:2019-07-17 15:24:35
【问题描述】:
我创建了一个使用 JQuery 完成的网站,但我现在正在尝试学习反应,但不确定如何使用 axios 连接我的后端 API。有谁知道这相当于 axios。
$("#log-form").submit(function (event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: '/users/login',
dataType: 'json',
data: {
'user_name': event.target.inputUsername.value,
'password': event.target.inputPassword.value
},
success: function(token){
$(location).attr('href', '/feed' ); // Redirect to logged in page
},
error: function(errMsg) {
swal(
'Oops...',
errMsg.responseJSON.body,
'error'
)
}
});
});
【问题讨论】:
-
你试过什么? Try looking at some basic examples of using axios,当你尝试了一些代码和特定的问题陈述后回来。