I've been tinkering with a jquery autocomplete plugin today
I'm using Ajax to get the pull-down data back in the background, and then the egg hurts.
First of all, I'm using the thinkphp framework.
First of all, we must return the JSON data.
And then I just
return json_encode($end,JSON_UNESCAPED_UNICODE);
Results The front-end JS plugin has been an error, presumably to say that the returned JSON data is not legal
And then I tried it for a long time.
echo json_encode($end,JSON_UNESCAPED_UNICODE);
The result can be, I also baffled its solution Ah, please master explain, things clearly exactly the same as a echo a return how there is a difference
Reply content:
I've been tinkering with a jquery autocomplete plugin today
I'm using Ajax to get the pull-down data back in the background, and then the egg hurts.
First of all, I'm using the thinkphp framework.
First of all, we must return the JSON data.
And then I justreturn json_encode($end,JSON_UNESCAPED_UNICODE);
Results The front-end JS plugin has been an error, presumably to say that the returned JSON data is not legal
And then I tried it for a long time.echo json_encode($end,JSON_UNESCAPED_UNICODE);
The result can be, I also baffled its solution Ah, please master explain, things clearly exactly the same as a echo a return how there is a difference
The JS callback requires a value, and PHP must only output a JSON string to receive it.
This is the concept of HTTP protocol, request sending and response acceptance. There must be a value in the content returned by response. Ajax to get to.
and PHP is output JSON string statement has the Echo function has exit () Die ()
As for the return of the controller layer inside the thinkphp. Just returned to the thinkphp core controller class. Finally, if the controller does not have any output, the response content is empty.
SF has a similar problem before: the difference between Echo and return
Say it again, OK:
return
is to return the result to the PHP program.
echo
is the AJAX response.
Really drunk, the landlord saw the front-end JS error, you can not by the way to see the return value of Ajax? What is the problem is not a glance at things.
The right approach should be
exit(json_encode($end,JSON_UNESCAPED_UNICODE));
return
is returned in the function.
echo
is the output to the page.
TP has a $this->ajaxreturn () method, which can be used directly.