嗨,我试图在状态代码的基础上显示错误消息,但不幸的是在控制台得到响应,而不是在客户端显示



下面是我的客户端代码

const submitFormData = (evt) => {
evt.preventDefault()
Swal.fire({
title: 'Are you sure you want to publish post?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, Confirm!'
}).then(async (result) => {
if (result.isConfirmed) {
const res = await companyJobPost(input)
console.log("res", res)
if (!res.status === 200) {
alert("JobId must be unique ")
return
}
else {
alert("Job posted successfully")
}
}
})
}
Here is the res from the console

{data:{…},status: 200, statutext: 'OK', headers:{…},config:{…},config: {url: 'http://localhost:8080/company/jobPost', method: 'post', data: '{"companyId"; "610a4313ea5428258c5e689d"; "company "; ";1- 2-year";terminalDegree"; "; bachelor "}', headers:{…},transformRequest: Array(1),…}data:{批准:false,拒绝:false,状态:'pending', _id: '6145fd8a77b1ba2f80403241', jobId: '01w4',…}headers: {content-length::'430',内容类型:'application/json;charset=utf-8'}request: XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: 1,…}status: 200statusText: "OK"[[Prototype]]: Object

<代码>

您使用了错误的警报。我想这应该能解决你的问题。

CC_2

alert(JSON.stringify(yourObjectVariable)); 

阅读https://reactnative.dev/docs/alert获取更多信息。

#更新答案

PP_4