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 6725861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:51:27+00:00 2026-05-26T09:51:27+00:00

I am trying to inject an html string into a div, but am having

  • 0

I am trying to inject an html string into a div, but am having a problem. The return from csharp method I pass is not what what is showing up in the div.

JavaScript Function…

$.ajax({
    type: "POST",
    url: "MainPage.aspx/mapBuildLegend",
    data: dataOut,
    contentType: "application/json; charset=utf-8",
    dataType: "text",
    success: function (text) { $('#divLegend').html(text); },
    error: function () { alert('Could Not Load Legend!'); }
});

String Returned from C Sharp Web Method

    "<table><tr><th>Color</th><th>Range</th></tr><tr><td><div class='divColorSwatch' style='background-color:#D3D3D3;'></div></td> <td> <div class='divColorLabel''>0 To 4.9999</div></td></tr><tr><td><div class='divColorSwatch' style='background-color:#FFC8C8;'></div></td> <td> <div class='divColorLabel''>5 To 9.9999</div></td></tr><tr><td><div class='divColorSwatch' style='background-color:#FF9696;'></div></td> <td> <div class='divColorLabel''>10 To 14.9999</div></td></tr><tr><td><div class='divColorSwatch' style='background-color:#FF6464;'></div></td> <td> <div class='divColorLabel''>15 To 19.9999</div></td></tr><tr><td><div class='divColorSwatch' style='background-color:#FF3232;'></div></td> <td> <div class='divColorLabel''>20 To 24.9999</div></td></tr><tr><td><div class='divColorSwatch' style='background-color:#FF0000;'></div></td> <td> <div class='divColorLabel''>25 To 100</div></td></tr></table>"

What ends up in my div…

    {"d":"\u003ctable\u003e\u003ctr\u003e\u003cth\u003eColor\u003c/th\u003e\u003cth\u003eRange\u003c/th\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cdiv class=\u0027divColorSwatch\u0027 style=\u0027background-color:#D3D3D3;\u0027\u003e\u003c/div\u003e\u003c/td\u003e \u003ctd\u003e \u003cdiv class=\u0027divColorLabel\u0027\u0027\u003e0 To 4.9999\u003c/div\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cdiv class=\u0027divColorSwatch\u0027 style=\u0027background-color:#FFC8C8;\u0027\u003e\u003c/div\u003e\u003c/td\u003e \u003ctd\u003e \u003cdiv class=\u0027divColorLabel\u0027\u0027\u003e5 To 9.9999\u003c/div\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cdiv class=\u0027divColorSwatch\u0027 style=\u0027background-color:#FF9696;\u0027\u003e\u003c/div\u003e\u003c/td\u003e \u003ctd\u003e \u003cdiv class=\u0027divColorLabel\u0027\u0027\u003e10 To 14.9999\u003c/div\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cdiv class=\u0027divColorSwatch\u0027 style=\u0027background-color:#FF6464;\u0027\u003e\u003c/div\u003e\u003c/td\u003e \u003ctd\u003e \u003cdiv class=\u0027divColorLabel\u0027\u0027\u003e15 To 19.9999\u003c/div\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cdiv class=\u0027divColorSwatch\u0027 style=\u0027background-color:#FF3232;\u0027\u003e\u003c/div\u003e\u003c/td\u003e \u003ctd\u003e \u003cdiv class=\u0027divColorLabel\u0027\u0027\u003e20 To 24.9999\u003c/div\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cdiv class=\u0027divColorSwatch\u0027 style=\u0027background-color:#FF0000;\u0027\u003e\u003c/div\u003e\u003c/td\u003e \u003ctd\u003e \u003cdiv class=\u0027divColorLabel\u0027\u0027\u003e25 To 100\u003c/div\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e"}

Thank you for any help,

Eric

  • 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-26T09:51:28+00:00Added an answer on May 26, 2026 at 9:51 am

    Looks like it’s returning JSON. Try

    $('#divLegend').html(text.d);
    

    UPDATE

    If that doesn’t work, then you need to just convert the returned text into a JSON object first:

    var jText = JSON.parse(text);
    $('#divLegend').html(jText.d);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to Inject a seam component into another, auto creating it. But
I'm trying to inject some CSS that accompanies some other HTML into a C#
I'm trying to inject some additional markup in the response but its not outputting
Hi i am trying to inject a dictionary of interfaces but am getting an
I am trying to inject inside repeaters items, the problem is that the row
I met a problem when trying @Singleton of Guice: import com.google.inject.Singleton; @Singleton public class
I want to inject some HTML into some websites with a Chrome extension, and
I am trying to inject json into my backbone.js app. My json has &quot;
I'm trying to inject a Map into a Grails controller. I want to inject
I am trying to understand the javax.inject package and I am not clear what

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.