/    Sign up×
Community /Pin to ProfileBookmark

Async problems

Hello,

New member here and amatuer js programmer….

have a form with button that I want to call serially, meaning I want the first, sendToOptimize() to complete, and then call the second, sendRequest3

Problem I’m having is the second function gets called before the first completes. The first function does a db join etc. that the second would read. Since it reads before the join, all my data is “one click old”….
I read that synchronous ajax is “bad” so I’m looking for advice/input as how to have the second function run after the first is completed.

I tried changing the “onSuccess:” call to onComplete but it does not seem to do anything…

Also tried adding the second function (straight off the web) as a dummy function to be called from the first, but no avail….


——————

<input type=”button” value=”Run Model” sendToOptimize(); sendRequest3(form1, ‘http://localhost:8080/IUNG/tml/optimize_w_map1.tml‘); “><br>

function sendToOptimize()
{
// new Ajax.Updater(“model_output”, ‘/IUNG/tml/optimize.tml’, {
// changed to direct url
new Ajax.Updater(“model_output”, ‘/optimize’, {
asyncronous: ‘false’,
method: ‘get’,
insertion: Insertion.Bottom,
parameters : Form.serialize(“form_im”),
onSuccess: function(cursor_update) {document.body.style.cursor = ‘default’},
onFailure : function(resp) {
alert(“Oops, there’s been an error.”);
}

});
var model_output = $(‘model_output’)
model_output.innerHTML = “<b>Model is running, please wait…</b><br>”
// seems prototype needs function defined inside to call external
// when this is used we remove the call from the button above
function
function dummy_function() {
sendRequest3(form1, ‘/render_optimize’);
document.body.style.cursor = ‘wait’;
}
}

function sendRequest3(frm, file) {
var rnd982g = Math.random();
var str = “”;
if(str = getForm(frm)) {
req.open(‘GET’, file+’?’+str+’&rnd982g=’+rnd982g);
req.onreadystatechange = handleJson;
req.send(null);
}
return false;
}

ANyway, would appreciated some help…

regards,
nick

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @olNick spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...