Forum Discussion
_anomDiebolt_
8 years agoQrew Elite
I ran your code through jsbeautifier.org with 2 space indent and placed it online via pastebin.com:
https://pastebin.com/FbEsPDZ6
This is the preferred way to share code as the forum often messes it up.
There are a number of things you could do to improve your code
(1) use $.ajaxSetup({data: {apptoken: apptoken}}); to avoid appending the apptoken to every AJAX call
(2) I am not sure why you are using $().each() as there will only be once qdbapi element in the XML response:
Note $(<a>).find(<b>) is equivalent to $(<b>, <a>)
(3) your utility function getQueryVariable should probably return undefined instead of false and should probably do some URL decoding. I would look to the internet for a better version (there are dozens of these floating around)
(4) $.when(...) is probably better used with a list of promises all of which have to resolve before the when resolves. Note this code:
but I assume it works for your purposes. If you goal is to automatically get the code to execute after clicking the save button you could use this technique to do so:
Save and Scooby Doo Technique
https://community.quickbase.com/quickbase/topics/what-is-the-save-and-scooby-doo-technique
https://pastebin.com/FbEsPDZ6
This is the preferred way to share code as the forum often messes it up.
There are a number of things you could do to improve your code
(1) use $.ajaxSetup({data: {apptoken: apptoken}}); to avoid appending the apptoken to every AJAX call
(2) I am not sure why you are using $().each() as there will only be once qdbapi element in the XML response:
$(xml).find('qdbapi').each(function() {
Note $(<a>).find(<b>) is equivalent to $(<b>, <a>)
(3) your utility function getQueryVariable should probably return undefined instead of false and should probably do some URL decoding. I would look to the internet for a better version (there are dozens of these floating around)
(4) $.when(...) is probably better used with a list of promises all of which have to resolve before the when resolves. Note this code:
var promise = $.get(url);is largely equivalent to:
$.when(promise).then(function(xml) { ...
$.get(url).then(function(xml) { ...
but I assume it works for your purposes. If you goal is to automatically get the code to execute after clicking the save button you could use this technique to do so:
Save and Scooby Doo Technique
https://community.quickbase.com/quickbase/topics/what-is-the-save-and-scooby-doo-technique