Script should not be appended if there is no html or body tag

I've encountered some issues where the script is injected where it should not.

Here, it's an action cached by rails and returned as HTML, but it's json data.

Anyway, I don't think the script should be injected if there is no explicit html or body end tag.

What do you think ?

Thanks