I see an error and ... something confusing.

The error is that you're using "this" to refer to the li inside the
success handler but it's gone out of scope. Commonly, people will
create a var "self" and assign "this" to it so as to refer to the
proper object inside a deeper scope.

The confusing bit is that you're instructing jQuery to make an AJAX
request for each LI *as the page is loading*. Normally, you'd create a
handler that does this upon the user's action of some sort (eg. a
click).

I'm more comfortable using $.ajax() so I'll use that here.

$(function()
{
        $("li").click(function()
        {
                var self = this;
                $.ajax({
                        url: "ajax_parser_update.php",
                        data: $(self).text(),
                        success:
                                function(data)
                                {
                                        $(self).append(data);
                                }
                });
        });
});

But, without a use case it's difficult to say for sure what you need.
Could you describe how and why these LIs should be updated?

On Sat, Aug 22, 2009 at 5:55 AM, Harri<h4rrison.ja...@gmail.com> wrote:
>
> Hi,
> I've used a few jquery things before, but I haven't a clue when it
> comes to javascript, so I've mainly just modified variables here and
> there. This is my first attempt at actually writing something, and
> well.....its not working :P
>
> Im trying to send an ajax post to an external file, which simply
> returns 'Complete' after updating the db. My html gives me an ul, with
> li elemnts, representing names of comics. Anyway heres my code, Id
> just like someone with more experience than me to tell me if im doing
> anything wrong:
>
>                $(function() {
>                        $("li").each(function(){
>                                $.post("ajax_parser_update.php", {query: 
> $(this).val()},
>                                function (data) {
>                                        $(this).append(data);
>                                });
>                                return false;
>                });
>                });
>
> Thanks,
> Harrison
>

Reply via email to