Hi MorningZ:

   I think your first approach is better for me.
   Finally I do:

beforedelete: function(NODE)// before delete - should return true |
false
{
        $.ajax({
                type: "POST",
                url: "/goicms/admin/removenode",
                async: false,
                data: "node=" + NODE,
                success: function(data)
                {
                          if (data == 1)
                              isOK = true;
                          else
                               isOK = false;
                });

        return  isOK;
}

Thank you very much for your help.




On 9 oct, 14:23, MorningZ <[EMAIL PROTECTED]> wrote:
> When you call "$.get". it does it *asynchronously*, meaning it goes
> off and makes the Ajax call but does not wait for it to get back with
> a result before continuing....
>
> You have two choices:
>
> 1) Use the more general "$.ajax" call and run your remote code
> synchronously (yuck! you'll potentially hang up the user's browser)
>
> 2) Learn about callbacks (which is the event raised *when* the $.get
> call does return)
>
> So like if your code is like:
>
> if (beforeDelete(NODE)) {
>      // Do something if true}
>
> else {
>      // Do something if false
>
> }
>
> to something like
>
> $.get(
>       "/isdeletable",
>       { 'node': [ NODE ]} ,
>       function (data) {
>            if (data == 1) {
>                   // Do something if true
>            } else {
>                   // Do something if false
>            }
> );
>
> On Oct 9, 6:49 am, nomen <[EMAIL PROTECTED]> wrote:
>
> > Hi all:
> >   I´m new to JQuery, so maybe i´m doing something badly.
>
> >   I have a previously defined javascript tree, i´m rewriting the code
> > to use ajax.
>
> >   This tree has a function
> >         beforedelete: function(node)
> >    If this function returns false, no node will be deleted in user
> > interface. If sends true, the node is deleted.
>
> >    I need to use $.get to decide if the tree node is deletable or not,
> > so i write this code:
>
> >  beforedelete: function(NODE) // before delete - should return true |
> > false
> >  {
> >          isOK = false;
> >          $.get("/isdeletable", { 'node': [ NODE ]} ,
> >                         function (data)
> >                         {
> >                                 if (data == 1)
> >                                          isOK = true;
> >                                 else
> >                                          isOK = false;
>
> >                         }
> >         );
> >         return  isOK;
> >  }
>
> >   isOK is a global variable.
> >   I can get the result (for the moment simple 0 or 1) from the server
> > side script. It works correctly.
>
> >   The problem is that beforedelete finished his work before i get the
> > data from the server (i discover it putting an alert before the
> > return).
> >    So it seems that this method is not valid, but i need to analyze
> > the answer and that beforedelete sends the correct value.
>
> >   What is the way to do it?
> >   Thank you in advance.

Reply via email to