Question

I would like to isolate a part of my responseText in Jquery and Ajax.

$.ajax ({
  url : "/controller/action",
  complete : function (xhr, result)
  {
    if (result != "success") return;
    var response = xhr.responseText;
    var title = $(response).find("p");
    title.appentTo ("#description");   
  }
});

I works great for response but doesn't when I try to isolate the part between

Can I use : .find("p")?

Was it helpful?

Solution

Seems like you have to correct some typos, but I don't agree entirely with the suggestion. To me it should be:

$(title).appendTo('#description');

[note that the tile is inside $()] cause appendTo can accept selectors too

OTHER TIPS

Why don't you use success handler because you are not doing if the response is not success?

$.ajax ({
  url : "/controller/action",
  success: function (response)
  {
    if (result != "success"){ 
       return;
    }

    var title = $(response).find("p");
    title.appendTo("#description");   
  }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top