I have been playing a jqueryautocomplete plug-in today. I used ajax to get the drop-down data from the background, then it hurts. first, I use the thinkphp framework. first, I must return json data. then I will returnjson_encode ($ end, JSON_UNESCAPED_UNICODE );... A jquery autocomplete plug-in has been playing around today
I used ajax to get the drop-down data from the background.
First, I use the thinkphp framework.
First, it must return json data.
Then I will
return json_encode($end,JSON_UNESCAPED_UNICODE);
The front-end js plug-in always reports an error, which means that the returned json data is invalid.
Then I tried to use it after a long time.
echo json_encode($end,JSON_UNESCAPED_UNICODE);
The result is okay, and I can't explain it. please explain how the same echo and return are different.
Reply content:
A jquery autocomplete plug-in has been playing around today
I used ajax to get the drop-down data from the background.
First, I use the thinkphp framework.
First, it must return json data.
Then I willreturn json_encode($end,JSON_UNESCAPED_UNICODE);
The front-end js plug-in always reports an error, which means that the returned json data is invalid.
Then I tried to use it after a long time.echo json_encode($end,JSON_UNESCAPED_UNICODE);
The result is okay, and I can't explain it. please explain how the same echo and return are different.
JavaScript callback requires a value. php must output a json string to receive the value.
This is the concept of http protocol, request sending and response acceptance. The returned content of response must have a value. Ajax can be obtained.
Php outputs json strings with the echo function and exit () die ()
For the return of the controller layer in thinkphp. Only the thinkphp core controller class is returned. Finally, if the controller does not have any output, the response content is empty.
There was a similar problem before SF: The difference between echo and return
Again:
returnReturns results to the PHP program.
echoIs the Ajax response.
I was so drunk that I couldn't take a look at the ajax return value if I saw a front-end js error? What is the problem.
The correct method should be
exit(json_encode($end,JSON_UNESCAPED_UNICODE));
returnIs returned in the function.
echoIs output to the page.
TP has a $ this-> ajaxReturn (); method, which can be used directly.