By default, any code that you put after the $.post(); part will be
executed immediately after $.post() is executed. That is, it will not
wait for the AJAX response. You would not be able to do the "do
something with data here" part correctly. To do so, you can using
jQuery's $.ajax() function, which allows an option parameter called
'async'. By setting this to 'false', the AJAX will not execute
asynchronously, meaning the rest of your code will wait for your
request before continuing.
Read here for more info:
http://docs.jquery.com/Ajax/jQuery.ajax#toptions

function disableTips ()
{
        var someVar = null;

        $.ajax({
                url: 'test.php',
                type: 'post',
                data: {id:id_val},
                async: false,
                success: function(data) {
                        someVar = data;
                }
        });

      alert(someVar);
}



On Jun 12, 4:02 am, "jef...@gmail.com" <jef...@gmail.com> wrote:
> $.post("test.php", { func: "getNameAndTime" },
>   function(data){
>     process(data);
>   });
>
> Is one of the examples given for Jquery.
>
> Now I am trying to implement Jquery Ajax instead of a custom class we
> have here so am trying to catch on so bear with me.
>
> Above, it shows POST variable "func" containing "getNameAndTime" as a
> value correct? So if I wanted to pass along say names I would pass
> along {first: "Bob", last: "Smith"}?
>
> I find adding the callback function right in the call a little awkward
> (probably because I'm new to Jquery). Basically I was adding a onClick
> function to a link to a function (function test()) and inside I was
> going to add this jquery code. I just wanted to then have the returned
> data at my disposal in a variable but it looks like I need to pass it
> somewhere else?
>
> I basically wanted to do this:
>
> function disableTips ()
> {
>         $.post("./test.php", {id : id_val}, function(data){
>         something here?
>         }
>         }) ;
>
>       then do something with data here
>
> }
>
> Am I going about it completely the wrong way with jquery?

Reply via email to