What is the difference between echo and return in returning ajax results? {Code...} can be used with echo above, but not with return! 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);
The above can be done with echo, but not with return! Solution
Reply content:
Echo: Used to output results
Return: returns the processing result.
No output results. how does js receive them?
Return is the return value in the function to facilitate subsequent calls.
No.
Return is the execution result set of the return method, and no output is made.
Echo is to output this json
Ajax json object needs to obtain the parsed output string
It is easy to say that you are a json parsing machine. after your code is run and then return, nothing is displayed on the stray machine.
Only by outputting the results will your eyes be able to understand what you can guess.
Return is not returned to js ......
Think about the function in PHP, the return value is returned to javascript ......
This reminds me of a new person who used to bring PHP exceptions to the browser ......
return
Returns results to the PHP program.
echo
Is the Ajax response.
Echo indicates that the output result is sent to the requester, and return indicates that the returned value is not returned to the caller. Ajax obtains data based on the page value.
The above is a detailed description of the differences between echo and return code instances in PHP. For more information, see PHP Chinese network (www.php1.cn )!