1

我想在 Jquery 和 Ajax 中隔离我的 responseText 的一部分。

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

我工作得很好,response但当我试图隔离两者之间的部分时却没有

我可以使用 :.find("p")吗?

4

2 回答 2

2

似乎你必须纠正一些错别字,但我并不完全同意这个建议。对我来说应该是:

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

[注意磁贴在 $() 内] 导致 appendTo 也可以接受选择器

于 2012-01-23T21:04:23.297 回答
0

为什么不使用success处理程序,因为如果响应不是,您就没有这样做success

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

    var title = $(response).find("p");
    title.appendTo("#description");   
  }
});
于 2012-01-23T20:58:52.637 回答