Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8367059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:04:05+00:00 2026-06-09T13:04:05+00:00

Scenario I’m writing a web application, MVC in my case, and I need to

  • 0

Scenario

I’m writing a web application, MVC in my case, and I need to update a specific container with the response from a get request, sometimes I want to filter the elements and find an element from the response to place in the original container.

How can I do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:04:06+00:00Added an answer on June 9, 2026 at 1:04 pm

    I was building a web application when I needed to partially update my content asynchronously

    So I came up with a function which might suits your needs too.

    Basically it will perform a get request to the url provided, it has the standard jQuery callbacks: onSuccess, onError and onComplete, and you can filter() and find() on the result as well as specifying the container to place the response into.

    Assume you have this on your page:

    <div id="myContentWrapper">
        <div class="myContent">
            <h1>This is the content I want to update.</h1>
        </div>
    </div>
    

    And the response of the request returns this:

    <html>
        <!-- some html -->
        <div id="filterId">
            <div class="findClass">
                <h1>This is the content I want to inject!</h1>
            </div>
        </div>
        <!-- some more html -->
    </html>
    

    Now you can update it wiring the function to myButton click event:

    $("#myButton").click(function () {
        loadContent("/Controller/Action", //url
        "#filterId", ".findClass", //filter & find
        "div#myContentWrapper div.myContent", //container to update
        function () { //success callback
            alert('Success!');
        }, function () { //error callback
            alert('Error :(');
        }, function () { //complete callback
            alert('Complete');
        });
    });
    

    Easy enough, now the function will do the rest of the work for you:

    function loadContent(url, filter, find, container, 
                         onSuccess, onError, onComplete) {
        var htmlResult;
        $.ajax({
            url: url,
            type: "GET",
            success: function (data) {
                htmlResult = data;
                if (onSuccess && typeof onSuccess == "function") {
                    onSuccess.call(this);
                }
            },
            error: function () {
                htmlResult = "<h1>An error occurred!</h1>";
                if (onError && typeof onError == "function") {
                    onError.call(this);
                }
            },
            complete: function () {
                if (filter != null) {
                    if (find != null) {
                        $(container).html(
                            $(htmlResult).filter(filter).find(find).html());
                    } else {
                        $(container).html($(htmlResult).find(find).html());
                    }
                } else {
                    $(container).html(htmlResult);
                }
                if (onComplete && typeof onComplete == "function") {
                    onComplete.call(this);
                }}});}
    

    Maybe you don’t want to filter or find something in the response, so you could do:

    loadContent("/Controller/Action", null, null, 
    "div#myContentWrapper div.myContent", 
    function() {
        alert('Success!');
    }, function () {
        alert('Error :(');
    }, function () {
        alert('Complete');
        });
    

    Or maybe you don’t need any callbacks:

    //This is the basic function call, these parameters are required
    loadContent("/Controller/Action", null, null, 
        "div#myContentWrapper div.myContent", 
        null, null, null);
    

    There you go, now you can easily update any content you want asynchronously, feel free to tweak this as needed, also you could use a request type parameter so you can GET or POST, or even adding a loading image container’s id so you can display it when you enter the function and hiding it on the complete callback of the $.ajax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario : I have an ASP.NET MVC application developed in Visual Studio 2008. There
Scenario I have an web application which needs some calculations and processing on data.
Scenario I need to update a SQL 2008 database daily via a spreadsheet (the
Scenario : I'll try to put an analogy with the loan broker example from
Scenario: Third party web service returns datetime in two separate fields i.e. date and
Scenario: During Hive COnfiguration, when I enter hive-dir-path$ bin/hive, I get the error as:
Scenario I’m writing a Chrome extension / userscript to add a little usability to
Scenario: I have imported the data from SQl Server to HDFS. The data stored
Scenario: I want to develop an application.The application should be able to connect to
Scenario A SOAP web service provides an interface for retrieving documents and data. Security

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.