
I mentioned this over on the API forum but I think I've now got a better handle on the problem so I thought I'd report it here. The Enable/Disable button for API scripts has a nasty race condition bug which means it basically never works for me (and others). The handler looks like this (thank you for not obfuscating your JS!):
Cheers,
Lucian
$(".togglescript").on("click", function() { var $parent = $(this).parents(".script"); var scriptid = $parent.attr("id").replace("script-", ""); var othis = this; if($(this).hasClass("active")) { $.post("/campaigns/toggle_script/730264/" + scriptid, {state: "inactive"}, function(data) { notifier.child("scriptrestart").set(true); notifier.child("errorlock").set(null); $(othis).removeClass("active").addClass("inactive").text("Enable Script"); }); } else { $.post("/campaigns/toggle_script/730264/" + scriptid, {state: "active"}, function(data) { notifier.child("scriptrestart").set(true); notifier.child("errorlock").set(null); $(othis).removeClass("inactive").addClass("active").text("Disable Script"); }); } window.location.href = window.location.href + ""; });The problem seems to be that window.location.href line at the bottom. I think in a lot of cases, the page is getting refreshed before the post to disable/enable the script even gets off my computer (this will no doubt depend on the latency of the connection and the speed of the computer). Consequently, most of the time the button just doesn't work at all. If I put a breakpoint in firebug it works flawlessly, because obviously there's then plenty of time for the request to be processed. Is there really any reason to refresh the page here? If there is, is there any reason why it can't happen inside the callback from the POST so you can be sure the request has gone through?
Cheers,
Lucian