search

Home  >  Q&A  >  body text

php - api returns prompt information. Does the front-end prompt the user with the prompt information returned by the api?

1. When the API interface returns data or returns an error message, the user is prompted with some relevant information, such as a form submission such as illegal parameters, and then a prompt that the form submission is successful. When I succeed in the background, all returns are uniform. success However, the front-end directly prompted success to the user, which led to the leader saying that Chinese characters such as success should be directly returned to the background. I was speechless. Can't the front-end define a set of information to be returned to the user? You have to use the backend to return. Our backend returns all the error codes. The prompt information plus the error code is only used for viewing when it is open to quickly locate errors, but the front end directly prompts the user to see it. Can you guys give me some advice?

淡淡烟草味淡淡烟草味2782 days ago691

reply all(6)I'll reply

  • 怪我咯

    怪我咯2017-05-16 13:10:58

    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...

    reply
    0
  • 迷茫

    迷茫2017-05-16 13:10:58

    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

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 13:10:58

    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.

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-16 13:10:58

    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.

    reply
    0
  • 为情所困

    为情所困2017-05-16 13:10:58

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

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 13:10:58

    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.

    reply
    0
  • Cancelreply