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, ‘
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