jQuery/ajax - Loading external Div's
Here I have the page already loaded... it hides until clicked. Once clicked the external page is triggered, opens and displayed dynamic content.
The problem is it's grabbing too much of the page... I only need the contents of 1 div... not the whole page...
help please... here's the code..
(function($){
$.am_get_item = function (item_id, size_id){
$.ajax({ url: "/order/item/" + item_id + "/" + size_id, success: function(data){
$(".item_form").hide();
$("#form_" + item_id).html(data);
/* $("#form_" + item_id).load("/order/item/" + item_id + "/" + size_id +开发者_如何学运维 "#show_item"); */
$("#form_" + item_id).slideDown("slow");
$("input#form1").keyup(function () {var value = $(this).val();$("div#ok").text(value);}).keyup();
}});
}
})(jQuery);
$("#form_" + item_id).each(function() {
$(this).html(data);
var div = $(this).find("div_i_want_selector").clone();
$(this).empty().append(div);
$(this).slideDown("slow");
});
from http://api.jquery.com/load/
Loading Page Fragments
The .load() method, unlike $.get(), allows us to specify a portion of the remote document to be inserted. This is achieved with a special syntax for the url parameter. If one or more space characters are included in the string, the portion of the string following the first space is assumed to be a jQuery selector that determines the content to be loaded.
So, basically, use load() function and add the specific div selector at the end of the url.
精彩评论