php - api返回提示信息 前端提示给用户一定要用api返回的提示信息吗?
淡淡烟草味
淡淡烟草味 2017-05-16 13:08:58
0
6
644

1、在API接口返回数据或者返货错误提示的时候 面临着像用户提示一些相关的信息 就比如说参数非法之类的表单提交 又到提示表单提交成功 我在后台成功都是统一返回success 然而前端就直接提示出success 给用户 导致领导说要直接后台返回成功之类的汉字 ,我表示很无语啊,难道前端就不可以定义一套返回给用户的一些信息吗?非得要用后端返回的,我们后端返回的都是加入了错误代码的,提示信息加错误代码 只是用于开放的时候观看 快速定位错误,但是前端直接就给提示用户看了。各位大神也和建议啊

淡淡烟草味
淡淡烟草味

reply all(6)
刘奇

If you can do it, just do what the leader says. If you can’t do it, just tell the front-end what the leader says and run away...

迷茫

First of all, the front-end should impose certain format restrictions on the input content, and make an illegal prompt before submission, and it cannot be submitted;
The back-end usually makes a regular HTTP error code. After the front-end and the back-end agree on this error code, the prompt information will be output It is done by the front-end, the front-end and back-end are separated and can be modified flexibly;
For example, the back-end returns 200, and the front-end receives 200 and prompts a prompt like XXXXX success

我想大声告诉你

Generally, the front-end does not involve logical judgment and is only responsible for display. Maybe you can return it like this:

{
    'status': 'success',
    'message': '登录成功'
}

That’s okay.

When I wrote the interface in the past, I returned the relative path of the image. I was also thinking that if the front end spliced ​​the domain name and the relative path, wouldn't it be a complete path? But it will increase the complexity of the front end.

给我你的怀抱

You just have to talk to the two front-end guys about this. It has nothing to do with the boss. What the boss wants is the final result. It’s up to you to decide how to do it. Just communicate with the final standards and what the final standards will be. You can talk to the front-end brothers. Let's talk like this. I will pass the code, status, and data data to you. You only need to judge the code and status. You will return relevant prompts and data data. All successes will be xxx, and failures will be xxx. Otherwise, every interface will transmit Chinese characters. , it’s a pain in the ass for you to judge on the front end.

为情所困

I usually return the status code from the interface. Then understand the meaning of the status code in the interface document. That’s ok

Ty80

Maybe your leaders don’t understand technology at all.
In principle, the back-end should not transmit server information to the front-end, but it doesn’t matter if it’s just a success or failure prompt. Tell the front-end students about where they went wrong, and they can communicate with you.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!