SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cant Update Dom after jQuery Ajax Request

    Hi,

    I'm trying to update my page with either a yes or a no, I'm using Ajax for the request to the server. The request works perfectly, however when I try to update the DOM with the server response using $(this).text(response.waiting); and $(this).html(response.waiting);.

    I've tried alert(response.waiting); and returns a valid response. So, the problem probably stems from the DOM.

    Code:
    $("#data a.waiting").each(function(i){
    	$(this).click(function() {
    		$(this).html('<img src="../img/loading.gif" id="loadwait" alt="Loading..." />').fadeIn("slow");
    		$.ajax({
    			type: "POST",
    			url: "waiting/ajax/",
    			data: "id=" + $(this).attr("name"),
    			dataType: "json",
    			success: function(response) {
    				$("#loadwait").hide();
    				$(this).show();
    				$(this).html(response.waiting);
    			}
    		});
    	});
    });
    I really need some help on this, feel free to throw any ideas forward.
    Thanks.

  2. #2
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi again,

    I've figured this out, I'm kicking myself now though because I should have seen it ages ago. The problem was a loss of scope, I fixed it by assigning var self = $(this);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •