troubleshooting Question

not sure if Jquery ajax is caching overlay UI

Avatar of Solutionabc
Solutionabc asked on
JavaScriptScripting LanguagesAJAX
20 Comments1 Solution741 ViewsLast Modified:
Hi,
I have a script that is using the UI tools overlay with some jquery ajax. the script is below.
http://flowplayer.org/tools/demos/overlay/trigger.html

The problem I am having doesn't seem to be with the ajax as it is returning the correct values and is checking the returned value (var msg) properly.

the script works like this:

1) When someone clicks an image it triggers statify()
2) jquery ajax than calls PHP to mark a record column in the DB as locked and open the overlay UI
3) when the overlay is closed it calls another PHP script to mark that same record as open.

The purpose of this is to prevent multiple people from editing the same record during the same period of time.

I can only get this error to happen after the first person locks the record and then unlocks it, while still keeping the page open without refreshing. Now when person 2 on a different computer comes and locks the record Person 1 should not get the overlay because ajax will show it as locked. BUT when person 1 clicks it they still get the overlay as if it is not locked.

I have troubleshooted the issue by inserting alert() all over the place to check the value of var msg in different places and have concluded that the ajax, nested ajax and if statement are functioning 100% accurately.

For some odd reason when " if (msg === "1")" FAILS it will still open the overlay UI.... it's like the broswer has cached the action of opening the overlay and doesn't listen to the IF statement that checks if it should display it or not.

Does anybody know the reason why, when the if statement "if (msg === "1")" FAILS it will still perform the actions inside of the statement as if it has PASSED?

oh yeah, and I have set the jquery ajax property "cache" to false ;)

thanks.
function statify(id){

/*
var data = $.get("lockdown.php?num="+id);
*/
$.ajax({
   url: "lockdown.php?num="+id,
   cache: false,
   success: function(msg){
   alert(msg);
   if (msg === "1"){
   alert(msg);
     var triggers = $('.modalInput').overlay({

	// some mask tweaks suitable for modal dialogs
	mask: {
		color: '#68DBA0',
		loadSpeed: 200,
		opacity: 0.9
	},load: true,

	closeOnClick: true,
	onClose: function(){
	javascript_countdown.setTimeLeft(0);
	alert("on close alert"+msg);
	 $.ajax({
   url: "stable.php?num="+id,
   cache: false
   
   
 });}, onLoad: function(){ //time to countdown in seconds, and element ID
javascript_countdown.init(180, 'javascript_countdown_time'); }

});
} else { alert("this is locked");}

   }
 });
document.getElementById('id').value = id;

}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 20 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 20 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros