4 ms·
Why wrap everything in json? Then you'll just have to decode it on the other end. Just use url parameters, it's what they are for: (new Image).src = '/erro
by ars 14y ago
Why wrap everything in json? Then you'll just have to decode it on the other end. Just use url parameters, it's what they are for:
(new Image).src = '/errors?m='+encodeURIComponent(m)+
'&f='+encodeURIComponent(f)+'&l='+encodeURIComponent(l);
This way it also works on browsers that don't have native JSON (old IE mainly, but also firefox before 3.5). And those are also exactly the browsers where you are likely to get errors since you are probably not testing using them.
- ricardobeat 14y agoCurrently it's usually easier to decode JSON than to parse a query string. Modify to taste. You don't need to encode the strings, the browser will do that for src.
- ars 14y ago> Currently it's usually easier to decode JSON than to parse a query string. I don't see how that could be when you anyway have to parse the query string to get the e parameter. It costs nothing extra to get additional parameters. > You don't need to encode the strings, the browser will do that for src. Not in my testing - if the error message includes an & it will appear to the webserver as a new url parameter. And actually that's a bug in your JSON version as well - you need to encode it before sending it.
- ricardobeat 14y agoYes, I overlooked that. The way I'm doing that right now is with a route /errors/$message, so there's no query string parsing going on. I also typed encode instead of stringify, and forgot to add a semi-colon after wrapping new Image in parentheses...