A detailed example of the difference between Echo and return in PHP

Source: Internet
Author: User
Tags php language php code examples
What is the difference between ECHO and return in returning AJAX results?

$.ajax ({        ...        Success:function (data) {            AddType = "Change";            var obj = json.parse (data);            Console.log (data);        }    })
$addID = $this->input->post (' Addid ');        $data = $this->address_model->getaddresslistinfo ($addID);        (1) Echo Json_encode ($data);        (2) return Json_encode ($data);

With echo on it, you can't use return! Solving

Reply content:

Echo: For output results
Return: Returning processing results

No output results, JS how to receive?

Return is the value returned in the function to facilitate subsequent calls

Definitely not.
Return is the execution result set of the returned method, and there is no output
Echo is the output of this JSON
Ajax JSON objects need to get the parsed output string

The simple truth is that you're a JSON parsing machine, your code runs out and then you return, and the rover doesn't show anything.
, only the output of the results, your eyes can see you guess can parse

Return is not returned to JS ...
You think about the PHP language function, return value returned to JavaScript ...
It reminds me of a new guy who used to throw PHP exceptions to the browser ...

returnis to return the result to the PHP program.
echois the AJAX response.

echo indicates the output to the requester, and return indicates that the return value does not output the result to the caller. Ajax is based on the value of the page to get the data.

The above is a detailed explanation of the Echo and return in PHP code examples of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.