Ftt wrote:
> Thanks for the tip! I've made the change. I have one last issue that
> maybe someone can help me with. Once I make the ajax.request, the
> request doesn't finish before moving on in my code and returning the
> wrong note.id....
>
>
It seems like you're not quite understanding the asynchronous concept of
ajax (without it, ajax would be jax). Any "moving on in your code"
needs to be done after onSuccess is called. The "return note.id" at the
end of saveNoteDb is wrong. You'll need to create two functions--see
example below.
-Ken
function saveNoteDb(note){
...
var ajaxinsert= new Ajax.Request(url, {
method: 'get',
parameters: {...},
onSuccess: function(transport) {
if (transport.responseText > 0) {
//note saved
note.status = 'saved';
note.id = 'note' + transport.responseText;
} else {
note.status = 'failed';
}
showNoteSaveStatus(note);
}
});
}
function showNoteSaveStatus(note) {
$(note)
.addClassName(note.status)
.update(note.status.capitalize());
};
// i don't know your html structure, but in this example:
// if saved with an id of 100, the note node would now
// have a class of "saved" an innerHTML of "Saved"
// and an id="note100"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---