CFAJAXPROXY and timing
Hello, everyone.
I'm using CFAJAXPROXY to call CFC's via JavaScript, and I've come across what I believe to be a timing issue.
Basically what I'm trying to do is use the same form for both INSERT and UPDATE to a database.
If it's an INSERT, the ID field is set to 0; if it's an UPDATE, the ID field is set to whatever ID is associated with the data pulled from the database. No problem.
I was using an IDENTITY field for the ID's but that created issues with another CFC (the one method that does either the INSERT or UPDATE, depending) so I've changed the ID columns so they are no longer IDENTITY - which means that I have to SELECT the max(ID)+1 for the next ID, if it's an INSERT.
I can't get the new ID when the form loads - who knows how many people will be using this form. So I'm trying to set it so that when the form submits, if the ID is 0, THEN run the SELECT max(ID)+1 to get the new ID.
But the lag between calling the CFC and getting the result is causing me to set the ID variable to UNDEFINED.
Here is some code:
var gpi = new cfc_getProjectInfo();
gpi.setHTTPMethod("POST");function submitForm() {
//blah blah blah
if(thisValue == 0) { // If new base, get next BASE_ID
gpi.setCallbackHandler(getNewBID);
gpi.setErrorHandler(myerrorHandler);
thisValue = gpi.getNewBaseID();
}
formObj[thisName] = thisValue;//blah blah blah
}
function getNewBID(BID) {
return BID;
}
The CFC method is returning a string, the new ID.
Any suggestions?
Thanks,
^_^
