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

  • Home
  • SEARCH
  • 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 3331474
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:35:16+00:00 2026-05-17T23:35:16+00:00

Using this ajax request I am returning a view fragment of populated html to

  • 0

Using this ajax request I am returning a view fragment of populated html to insert into a particular div within the layout.

my question is how do I declare #theDiv, I have the id available at the point where the view fragment is constructed (within the view_Controller).

Ideally I would return some json at the same time for instance, specifying:#theDiv, and any other parameters such as which nav bar element should be active etc….

    $.ajax({
      type: "POST",
      url: "controller/view_Controller.php",
      data: dataString,
      cache: false,
      dataType: "html",
      success: function(html){

           $('#theDiv').html(html)

        };
        });
  • 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-05-17T23:35:17+00:00Added an answer on May 17, 2026 at 11:35 pm

    You need to build an array of information on the backend:

    $data = array (
        'html' => $html,
        'target' => '#myDiv'
    );
    
    header('Content-type: application/json');
    echo json_encode($data);
    

    And in your JS:

    $.ajax({
        type: "POST",
        url: "controller/view_Controller.php",
        data: dataString,
        cache: false,
        dataType: "json",
        success: function(data){
           $(data.target).html(data.html)
        };
    });
    

    I don’t quite understand what you mean by specifying success and error — do you mean you want your script to be able to define the Javascript to be called on success?

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

Sidebar

Related Questions

I am loading feed-items into a ul using this jQuery .ajax() call, which I
I am using the ASP.NET AJAX Control Toolkit. Within this toolkit, I am only
I am using the jQuery $.ajax() function. I have put this into a parent
I am making this simple get request using jquery ajax: $.ajax({ url: https://app.asana.com/-/api/0.1/workspaces/, type:
I've got this textBox which triggers off an ajax request using jQuery: <asp:TextBox ID=postcodeTextBox
I'm doing an Ajax request in which I have the server returning well-formed HTML,
I'm using this helper method to turn my PartialViewResult into string and returning it
I am trying to make two ajax requests in parallel using jQuery like this:
I am using this Ajax script below to make cross domain Ajax calls which
I am using this JQuery Ajax Voting system guide as a rough reference but

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.