adam84 Posted May 18, 2011 Share Posted May 18, 2011 Hey, I am using JQuery, draggable and sortable on my site. The user does whatever they do and if they made a change I use ajax to update my database with the changes. I also do a page refresh every 60secs, and once the page refresh my JQuery functions stop working. When I drop an item, I want to id to be alerted. Before the refresh the page works fine, but after the refresh nothing gets alerted. To get the page working again, I need to refresh the page mulitple times manually. Anyone ever have this issue before? $( ".weekday" ).droppable({ drop: function( event, ui ){ alert($(ui.draggable).attr("id")); } }); Quote Link to comment https://forums.phpfreaks.com/topic/236783-jquery-and-reloading/ Share on other sites More sharing options...
nogray Posted May 19, 2011 Share Posted May 19, 2011 This could be because of loading from cache and execution time. If javascript runs before the dom is created, you will get errors. This happens even if you put the code below the dom element because new browsers execute cached or local javascript very fast. You would need ot make sure everything is loaded and use the ready function. Quote Link to comment https://forums.phpfreaks.com/topic/236783-jquery-and-reloading/#findComment-1217357 Share on other sites More sharing options...
adam84 Posted May 19, 2011 Author Share Posted May 19, 2011 I thought it might have been the cache, so I added something into the header section. Since I added that, the same issue has been happening, so I don't believe that was the problem. I believe everything is loaded because, I can drag items around my page just like normal, but the problem is when I drop the item, I try to get the ID of the dropped item, but when I alert the ID, nothing shows up, but if I refresh the page multiple times, it finally goes. Quote Link to comment https://forums.phpfreaks.com/topic/236783-jquery-and-reloading/#findComment-1217366 Share on other sites More sharing options...
nogray Posted May 19, 2011 Share Posted May 19, 2011 Is all your scripts in the bottom of the page (right above the </body> tag) and are you using the jquery ready function? Quote Link to comment https://forums.phpfreaks.com/topic/236783-jquery-and-reloading/#findComment-1217367 Share on other sites More sharing options...
adam84 Posted May 19, 2011 Author Share Posted May 19, 2011 Hmmm, I am using JQuery. my code is like this <html> <head> all my js and css imports here </head> <body> html code </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/236783-jquery-and-reloading/#findComment-1217372 Share on other sites More sharing options...
nogray Posted May 19, 2011 Share Posted May 19, 2011 Try to change it to the following and see if that's solve the problem <html> <head>CSS</head> <body> html code JS source files script tag $(document).ready(function(){ script code that require dom }); </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/236783-jquery-and-reloading/#findComment-1217717 Share on other sites More sharing options...
adam84 Posted May 19, 2011 Author Share Posted May 19, 2011 It still gives me an error. But after some testing, I think I know what the promlem is, but I am not sure what to do to fix it. I am using droppable, and when I drop an item, i use the 'drop' function. In that function I get the ID of the div I dropped and store it in a variable. I am also using sortable, I use the 'receive' function, in this function I parse the stored ID, because it is made up of two other ID. My error happens during the parsing of the stored ID. What I think is happening is that the droppable function is not getting called, so it is not stored that ID I need. The only fix I can think of is to get the item ID in the sortable function, but I couldn't find a solution to get the value I needed. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/236783-jquery-and-reloading/#findComment-1217725 Share on other sites More sharing options...
adam84 Posted May 20, 2011 Author Share Posted May 20, 2011 Solved, In the sortable:receive function, I need to use $(ui.item).attr('id') to get the current ID of the item being 'sorted'. Then I didnt need to use the droppable function which for some reason wasn't always getting called. Nonetheless, it works and all is well, thanks Quote Link to comment https://forums.phpfreaks.com/topic/236783-jquery-and-reloading/#findComment-1218254 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.