Ajax net::ERR_SPDY_PROTOCOL_ERROR
-
gydrus last edited by
Hello!
I've moved my site to new server (ubuntu 16.04 + nginx + php7.2) and got errors "POST https://food-tracker.ru/foods net::ERR_SPDY_PROTOCOL_ERROR" when it make ajax requests.
There are no errors at FireFox and Internet Explorer browsers! And at previous server with debian7+nginx+php5 all worked fine with latest Opera too. But now latest Opera is not working with the site. Can You help me? How to solve this problem?
Thank You! -
gydrus last edited by
Yeah! I've found the solution!
There is a request code example:$.ajax({ url: 'https://food-tracker.ru/foods', type: 'POST', dataType: 'JSON', data: {term: 'rjk'}, success: function (data) {console.log(data);} });
And there was server code:
protected function returnJSON($data) { header('text/html; charset=utf-8'); echo json_encode($data); die(0); }
The solution is to change line header('text/html; charset=utf-8'); to header('Content-type: application/json; charset=utf-8');
So, right working code is:
protected function returnJSON($data) { header('Content-type: application/json; charset=utf-8'); echo json_encode($data); die(0); }
Thanks for your attention!
P.S. But one question i still have: why was it working fine before, and brokes when just hosting changed?