Closed LoganS1 closed 6 years ago
Jesus. Include jQuery, intercept the form submit, create an ajax request and use the corresponding events to show a loading spinner until you hide it when the completion event fires
I'm going to be honest... I've never used AJAX. However, after a few tutorials, the current way of getting the image seems terrible. I am going to try to rewrite the code to use AJAX and then, if I can, add a loading spinner...
I tried using AJAX, but the response data would be encoded wrong. I looked for a solution, including plain XHR requests but to no avail (Most answers suggested changing the img's src attribute to the query directly as AJAX requests are meant to be HTTP or JSON/XML). I did however find that images have an onload and onerror events, which I used to display a simple CSS Loader in #11.
Ajax request are XHR request down the line. You misunderstood one thing:
AJAX requests are meant to be HTTP or JSON/XML
HTTP is the transport layer and will be used in every ajax/xhr request. Json/XML are just plain text data formats that are being transported on HTTP. It works the same with images. The webserver response with a mime type of an image, eg. image/png
, indicating to the browser that was received in that request should be interpreted/rendered as an image, encoded as png. When receiving json the mime is set to text/json
and xml would be text/xml
. You see where this is going
Thanks for the explanation @Kimmax
We need to show the user that the image is loading. Currently, the generate button is pressed, and then behind the scenes the "banner" img's src is being changed, which leaves the image remaining the same until the server responds. Maybe we can change to:
Is there any better ways of doing this?