Do Ajax request back-end PHP when the last output data why do I see people code is exit () rather than echo

Source: Internet
Author: User
Tags stop script
I usually write about it. echo $data
But I see people's code, a lot of them are exit($data)

Reply content:

I usually write about it.echo $data
But I see people's code, a lot of them areexit($data)

In general, you should use the Echo

The function of exit () is to force the termination of the script and use it to output the result with the benefit of avoiding subsequent code execution
For example, this situation:


  
   

When the $arg is 0 o'clock, only output ' failed ' does not output "It s Wonderful"

But using exit () has one place to note:
If a number is passed to it, the number will be treated as an exit status code and will not be exported to the client
Can see the official description: Http://cn2.php.net/exit

Because this interface API in general is finished after the output, in order to prevent some logical problems caused by the subsequent code to continue, simply use here to exit() output the results after the stop script. These are die some of the party's personal sentiment.

Anyway, I like exit.
1. Reduce the pressure of business logic judgment
2. Exit PHP script execution immediately after completion

exit() die()Personal experience is mainly after the output of the other output, affecting the client's normal receive parsing. Specific experiments can try, after the output after the output, the client received the data is wrong, small in the past to receive other people's projects have encountered, other friends said the same truth.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.