I have reached a point in my project where I cannot figure out how to use Ajax to keep going. I am new to using it, but I'd like to think that I have a basic understanding of how it works.
I run a site where I take form data and post it into a database, then send it to a webpage where it displays in bubbles. Users can then click these bubbles and pop open a modal which has more detailed information than what is presented in the small bubbles initially displayed.
I've hit a wall where I don't know how to open a modal and have it live update with new information without closing, no matter what the bubble they click is (which can have different types based on different form information sent).
And to be clear, by bubble I just mean a compact div that when clicked opens the modal.
I've looked everywhere for solutions to this, trying my best to apply knowledge from other projects to what I'm trying to accomplish with to no avail. Suggestions are appreciated!
I'd suggest you to look at the load method this should be enough for what you're trying to do.
If you want a live update of your modal you have two ways to go about this:
Implement polling in AJAX. Send an AJAX request every X seconds to the server and have it update the <div>'s in your modal.
Use WebSockets. This is far more complex, and solution 1. is probably good enough.
This Stack Overflow post should help get you started: jQuery, simple polling example
Related
I have a setup where I display a list of buttons and clicking on the buttons triggers a function that contacts a firebase database and gets the contents of a 'slide' that is to be shown to the user. The function then clears the content of the page and then creates elements from the data acquired from the database.
Now obviously, when I press back browser button once I've replaced the content, it won't take me back to the previous content. But I believe that my user's experience will be much better if it actually took them back to the list of buttons. I have two faint ideas on how to go about solving this problem but I'm lacking in specific details of how I can go about it.
Possible Solution 1:
Some way to dynamically create a new page using javascript and then serve it to the user.
Possible Solution 2:
Some way to simulate that the page has changed location. Maybe using anchoring links.
Let me know if you have any other solutions in mind or if you know how I should go about implementing these. Your help will be much appreciated. :D
I am new to flask.
How can I make it so that, upon a user clicking an image, a centered box containing a form appears in the div (without a page reload).
Is this possible just using javacript?
The answer to this has nothing to do with Flask. As you guess this would be achieved using JavaScript.
As it seems you do not have much knowledge of JavaScript i would suggest you start here : Mozilla Developer Network
Specifically you would need to look into event handlers, e.g. click handlers
You can also utilise a third party wrapper library like JQuery which will make interacting with DOM elements and events slightly simpler whilst your getting started with JavaScript.
These links will get you started or at least give you the knowledge to come back and ask a more directed question.
I have an application that navigates mostly with AJAX, and a section where a user can view information. I would like to track how long users are viewing different pieces of information. I want to assume that as long as they have the information loaded in the <div> they are "viewing" it. However when the user click on a link to "go to another section of the app" the <div> gets loaded with different content, the page doesn't actually redirect.
Does anyone have a solution for this, or at least some thoughts to help me see something I cannot see right now?
Thanks
Most analytics software will allow you track this. I have some experience with Google Analytics and it's something like:
ga.track("my-event", my_data);
Setting up a timer shouldn't be too hard. Put that code in the routine that handles content un/loading.
You should call some function when you update your content.
Since there is no "onchange" event for divs, you'll have to call your function after the ajax process: See this answer for more info.
However, if your content doesn't change according to ajax calls, you should trigger some event when your div changes.
Hope I helped you: without any code fragment I can't do more!
I'm trying to build a webform that has multiple stages. I'm patterning it off of the Stack Overflow / Stack Exchange flagging webform. The problem is, I'm not sure how to trigger the "next stage" action.
To illustrate, if one wants to flag a question on Stack Overflow, you click flag and then a popup prompts you to make a choice. If you choose the second option ("it doesn't belong here, or it is a duplicate") the form automagically takes you to a second screen.
First screen:
Upon click, it auto-redirects to:
The problem is that I don't know what the underlying trigger is. How does clicking that radio button send the end user to the next screen?
I tried checking the source, but I have a feeling I'm only seeing half the picture:
No amount of HTML tutorials I find have any practice example similar to this. I suspect this is JavaScript, but I can't find the linked .js file that would trigger these actions.
So: How does the webform auto-redirect upon click? As a follow-up, if it's using JavaScript, is there an HTML/CSS-only workaround I can use?
It might help to think about this at a lower level than frameworks. There are two ways one could make a multi-stage form.
The first (and generally older) way is to store the state on the server. Each stage of the form is actually a separate form, and the client's progress through the questionnaire is kept on the server (for example, as part of the session data).
The second way (the more modern one) is to use JavaScript, as you suspected. There is actually very little black magic in this case, and no auto-redirects on clicks at all. All you do is have one very long form where you show/hide some of the elements depending on the user's selections (of course, you could have multiple <form> elements which you show/hide).
Well, I'd use some sort of jQuery wizard plugin and adapt it to my needs. I did it very recently and it wasn't that hard. You should try SmartWizard 3.0, it's pretty active, the last release was about 2 months ago and the coders answered my questions pretty fast.
Here it is: https://github.com/mstratman/jQuery-Smart-Wizard
You can trigger the wizard to advance to the next step linking an event to the action of clicking the radio button.
Good luck :)
I want to integrate a function into my website, whereby if a user hovers their mouse on the name of a product, a box appears which will show the details of this product. For this I would preferably like to use either CSS or Javascript, I am not really sure how I would go about doing this though. Can anyone offer me some guidance please? I am currently using the JQuery UI with essentially the same code as the shopping cart code seen here :
http://jqueryui.com/demos/droppable/#shopping-cart
Thnk you very much for the help.
If you want to be fancy and use jquery, here is a list of popup plugins that you can browse.
If the product information isn't too complicated I would suggest using CSS as it is simpler. Also, you probably want to have the data already loaded, so the user doesn't have to wait a round trip to your server every time they mouse over a product. Here is a simple CSS popup tutorial.