Results 1 to 6 of 6

Thread: Is selector applied on client or server, when jQuery .load() is called with selector?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    36

    Question Is selector applied on client or server, when jQuery .load() is called with selector?

    jQuery has a .load() method, which is a convenient helper for retrieving HTML and loading it into an element. The load() method can also be configured to return only a portion of the source HTML. The sought porting is identified with a CSS selector.
    Code:
    $("#loadHere").load("HtmlPage3.html #fooBar");
    Is the whole file downloaded and the desired portion is selected on the client side? Or, does selection happen on the server side?

    Any suggestion, insight or reference is really appreciated!

    Best,
    - Nick

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Is selector applied on client or server, when jQuery .load() is called with selec

    It is server-side as stated on that page!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    36

    Re: Is selector applied on client or server, when jQuery .load() is called with selec

    Quote Originally Posted by Nightwalker83 View Post
    It is server-side as stated on that page!
    Where is it stated on the page (like, which paragraph)? I've re-read it, and couldn't find it the indication that the #selector is applied in the server side. I'm not trying to say that you are incorrect, I just want to understand better.

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Is selector applied on client or server, when jQuery .load() is called with selec

    .Load is just a shortcut to get an AJAX call and have the results of that call be placed into the HTML content of the element you specify.

    And it decides on doing a GET or POST based on how you call it.

    Don't you want more control?

    This is a lot more code but it also exposes a lot more paths for your consideration

    Code:
    objWebParam.ObText = strUN;
    objWebParam.username = window.username || "";
    objWebParam.message = objReturn.message || "";
    var strWebParam = $.toJSON(objWebParam);
    $.ajax({
        type: "POST",
        url: "WebService.asmx/BootPage",
        dataType: "json",
        data: strWebParam,
        contentType: "application/json; charset=utf-8",
        success: function (msg) {
            ajaxFinished(msg, sender, "bootpage", objWebParam);
        },
        failure: function (msg) {
            ajaxFinished(msg, sender, "failure", objWebParam);
        },
        error: function (msg) {
            ajaxFinished(msg, sender, "error", objWebParam);
        }
    });

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Is selector applied on client or server, when jQuery .load() is called with selec

    Oh - you are talking about this part

    We could modify the example above to use only part of the document that is fetched:

    $( "#result" ).load( "ajax/test.html #container" );

    When this method executes, it retrieves the content of ajax/test.html, but then jQuery parses the returned document to find the element with an ID of container. This element, along with its contents, is inserted into the element with an ID of result, and the rest of the retrieved document is discarded.

    jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document. During this process, browsers often filter elements from the document such as <html>, <title>, or <head> elements. As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser
    That tells me that if you put this #ID value into the call then the CLIENT SIDE will pre-process the data to be inserted so as to just have that small portion placed into the HTML of the destination element.

    [edit]
    I'm guessing on a simple page where you want to replace just a particular element in each call you would name the elements on the page the same as the "request" gives so that you could basically do ASP.Net UPDATE panels with ease.
    [/edit]

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Is selector applied on client or server, when jQuery .load() is called with selec

    I still go back to saying do it the real way - POST some AJAX to get some JSON back and loop it and place into the HTML.

    [edit]or at least do it with a passed parameter so you can send less HTML if you only want some small piece of it

    Example: Same as above, but will POST the additional parameters to the server and a callback that is executed when the server is finished responding.

    $( "#feeds" ).load( "feeds.php", { limit: 25 }, function() {

    alert( "The last 25 entries in the feed have been loaded" );

    });

    [/edit]

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width