Use POST, not GET, for generateVisualisationURL() #539
Replies: 2 comments
-
Unfortunately a POST isn't an option here as the documentation site is a static page - however there are some adjustments I have in mind that should shrink the JSON size substantially for those larger cases. I also plan on tweaking that page to have a textbox for input as a fallback |
Beta Was this translation helpful? Give feedback.
-
The static page limitation only applies if you use the one on the documentation site, right? Why not modify the library to use the babylonjs that you are already distributing with the library? In my own implementation I have done the following:
(For individual boxes I then renamed
to
(Yes, my bad, I'm accessing $_POST directly; on a public facing system one would of course use filter_input() and such.) While it makes sense for me to change babylonjs.html into a php file there are other options as well, e.g. node-ipc and similar javascript IPC based approaches. You could even base-64 encode the entire babylonjs code supplied with the library, slap on a Just my thoughts, for what they're worth. |
Beta Was this translation helpful? Give feedback.
-
The
generateVisualisationURL()
method is a great option, but in its current form it generates HTML code utilizing GET rather than POST requests. More often than not this creates URLs that exceed the maximum GET request length which fails ungracefully.So instead of
return 'https://boxpacker.io/en/master/visualiser.html?packing=' . urlencode(json_encode($this));
a better way might be something like
return '<form action="https://boxpacker.io/en/master/visualiser.html" method="post" target="_blank">' . PHP_EOL . '<input type="hidden" name="packing" value="' . htmlentities(json_encode($this)) . '" />' . PHP_EOL . '<input type="submit" value="Visualize" />' . PHP_EOL . '</form>' . PHP_EOL;
Note: while this example uses a submit form button, a JavaScript onclick() event handler combined with a regular URL (so as to mimic the output of the original code) would of course do as well.
// FvW
Beta Was this translation helpful? Give feedback.
All reactions