I know we can fetch a whole page when doing a GET request to the server, but what if i'm only interested in one particular div on that page, or more exactly in its content. Is the only option here is to fetch the whole page, get the div content from it using jquery find() for example? Or is there some possibility to set up some kind of query to the server to ask for this particular div to return.
Asked
Active
Viewed 7,760 times
2
-
Possible duplicate of [Extract part of HTML document in jQuery](https://stackoverflow.com/questions/2137811/extract-part-of-html-document-in-jquery) – Simon East Jul 03 '17 at 05:41
3 Answers
4
$.ajax({
'type': 'get'
...some params...
success: function(response){
$(response).find('div you are looking for').appendTo('div you want to append it');
}
});
For some params check jQuery ajax.
And answering your question: no, there is no way to get some parts of HTML without making special server-side service.

Michael Malinovskij
- 1,422
- 8
- 22
-
I understand this, but here as I stated before I download the whole page to the client, but i'd like to just download content that interests me to save bandwith, is that possible? – Alan Budzinski Dec 04 '12 at 23:49
-
Yes, with backend (server-side) service that'll return only parts that you need. For a regular page - server will always answer with full page content – Michael Malinovskij Dec 05 '12 at 12:07
-
Yeah that's what i thought, my intention was not to use any server side code, just regular request for a part of page, but it isnt possible :\ – Alan Budzinski Dec 05 '12 at 12:30
2
You might want to use a simpler form of jQuery's AJAX tool for this situation, .load
.
$('#wrapper').load(href+fragmentSelector, function() {
// callback to do stuff afterward
});
Here, we're loading content from the element with ID fragmentSelector
from the url href
into #wrapper
on our current page.
The entire page is still being requested, but only the content you request is returned.
Reference: http://api.jquery.com/load/#loading-page-fragments

Nick Sayre
- 36
- 5
1
You can use HTTP RANGE Header, but you can select a byte range to download and not a select content by DIV.
Example:
curl -r 0-1000 http://localhost -v
see Using the HTTP Range Header with a range specifier other than bytes?

Community
- 1
- 1

Domenico Briganti
- 551
- 5
- 7