utility icon indicating copy to clipboard operation
utility copied to clipboard

Ajax component can't handle responses bigger than 4096

Open highstrike opened this issue 11 years ago • 12 comments

If you have a response bigger than 4096 then the request type will be text/html instead of application/json

Tested on CakePHP 2.5.7

highstrike avatar Dec 15 '14 16:12 highstrike

I doubt this is anything that I am doing, the component is pretty straight forward. I'll look into it.

milesj avatar Dec 15 '14 18:12 milesj

found anything interesting? :)

highstrike avatar Dec 16 '14 09:12 highstrike

Nope. There's nothing in my code that would cause this. Looked into Cake's RequestHandler and didn't find anything there either. Perhaps it's a server configuration?

milesj avatar Dec 16 '14 18:12 milesj

If I put a header content type application json right in your case json on the last function then it works, but I don't wana do that, did you try it on your server and you could do more than 4096?

highstrike avatar Dec 16 '14 18:12 highstrike

I have not as I don't use CakePHP anymore and have no applications running it.

The RequestHandler sets the content type, not my component.

https://github.com/milesj/utility/blob/master/Controller/Component/AjaxHandlerComponent.php#L147 https://github.com/cakephp/cakephp/blob/master/lib/Cake/Controller/Component/RequestHandlerComponent.php#L667

You're passing JSON to respond() correct?

I also wonder if it's failing somewhere else in Cake, like the Response class.

https://github.com/cakephp/cakephp/blob/master/lib/Cake/Network/CakeResponse.php#L709

milesj avatar Dec 16 '14 19:12 milesj

I left your line 147 as it is, and im doing header('Content-Type: application/json'); before this line: https://github.com/milesj/utility/blob/master/Controller/Component/AjaxHandlerComponent.php#L186

Would you be willing to setup a simple cake project and try it out? Thank you :)

highstrike avatar Dec 16 '14 19:12 highstrike

When I have time (which won't be anytime soon).

I'd try debugging why RequestHandler/Response isn't setting the content type. Forcing the type through headers is the wrong approach.

milesj avatar Dec 16 '14 20:12 milesj

I know it's the wrong approach but it works.

I've tried debugging the request handler / response but got nowhere, at the end $ctype was application/json and $type was json. Even after all that the header content type in the browser was showing up as text/html... so can't really think of anything else =/

highstrike avatar Dec 16 '14 20:12 highstrike

I wonder if it's happening further down the chain.

What about setting the content type manually from your action? Instead of the component?

milesj avatar Dec 16 '14 20:12 milesj

haven't tried from controller / action yet... will do when i get to work tomorrow.

highstrike avatar Dec 16 '14 21:12 highstrike

Haven't had a chance to try it out yet, deadlines at work, last 2 days before holidays, couldn't even touch that specific cake project...

highstrike avatar Dec 18 '14 16:12 highstrike

Same. I probably won't be able to look at this until after the holidays.

milesj avatar Dec 18 '14 18:12 milesj