Using AJAX to get a div from the loaded content
I have been researching for the last two hours, and have found nothing.
Basically, I am using AJAX to load the page: "/API/images.vif" /API/images.vif's source:
<div id="recommended_images">This will appear in the featured images box.</div>
<div id="latest_images">This will appear in the latest images box.</div>
With ajax, I want to load the above code, and get the contents of "recommended_images" - is this possible? It's coming from a different domain, my other website, so I was thinking it开发者_StackOverflow wouldn't work due to security.
Assuming you get the security issue worked out, you have jQuery, and the contents of /API/images.vif have been saved to a variable named "result", you could do:
var $temp = $('<div></div>').append($(result));
var contents = $("#recommended_images", $temp).html();
The value of the "contents" variable will then contain any html in the recommended_images div.
Cross domain ajax calls can be done via 'jsonp'. Your backend needs to support it too.
Otherwise, yes the browser will not do it
精彩评论