Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading automatically from AJAX #22

Open
joshreade opened this issue Jul 28, 2017 · 3 comments
Open

Loading automatically from AJAX #22

joshreade opened this issue Jul 28, 2017 · 3 comments

Comments

@joshreade
Copy link

Hi there

Firstly thank you for what you have created, it is ideal for my current project.

I do have a question though. I have added the ability to save and load to a database via AJAX, which works fine. As the filename for the image also saves in the database when I click load it loads up the hotspots relevant to that image which is great.

What I am looking to do is remove the need to click the load button, and instead have the hotspots load automatically depending on what image is selected.

I managed to get this to work but it seemed to get caught in a loop and loaded hundreds of the hotspots on top of eachother. Do you know how this can be accomplished? Thanks

@vera-l
Copy link
Contributor

vera-l commented Aug 4, 2017

Hi,

I'm not sure I understand the question, you can attach your code to this topic, and I will try to resolve this problem.

@joshreade
Copy link
Author

joshreade commented Aug 4, 2017

Thanks for your reply.
So I have modified the localStorageWrapper so instead of saving/reading from local storage it now saves the coordinates in a database.

This works and I am able to save and load successfully.

I have also replaced the url/drag and drop section for loading images with a select menu of predefined images, this also works as expected.

What I would like is for the restore function to fire as soon as an image has been selected and loaded onto the canvas, instead of having to click 'load'.

When I tried this however it kept loading the hotspots in a loop and layering them on top of eachother.
I hope this makes sense, let me know if you need to see any more code.

Thanks

#loadurl is a hidden field with the filename of the image which is currently loaded into the canvas

var localStorageWrapper = (function() {

		   var KEY_NAME = 'SummerHTMLImageMapCreator';
          
            return {
                save : function() {
					
					
                    var result = areasIO.toJSON();
					console.log(areasIO);
					 $.ajax({
							url: 'savedata.php',
							type: 'post',
							data: {model:KEY_NAME,result:result},
							success: function(data){
								console.info('Saved in Database');
								alert('Saved');
							}
						});  
                    
                },
                restore : function() {

					
var namefromfield=$("#loadurl").val();
					namefromfield=namefromfield.split('|');
					var imgurl=namefromfield[0];
					var getmodelname=namefromfield[1];
					$.ajax({
							url: 'getdata.php',
							type: 'post',
							data: {imgurl:imgurl,model:getmodelname},
							success: function(data){
								console.log(data);
								   areasIO.fromJSON(data);
							}
						}); 
					
					
       
                }
            };
        })();

@summerstyle
Copy link
Owner

I need to see all changes, incl. menu of predefined images

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants