summer icon indicating copy to clipboard operation
summer copied to clipboard

Loading automatically from AJAX

Open joshreade opened this issue 8 years ago • 3 comments

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

joshreade avatar Jul 28 '17 07:07 joshreade

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.

vera-l avatar Aug 04 '17 15:08 vera-l

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);
							}
						}); 
					
					
       
                }
            };
        })();

joshreade avatar Aug 04 '17 15:08 joshreade

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

summerstyle avatar Aug 13 '17 18:08 summerstyle