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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:12:23+00:00 2026-06-11T22:12:23+00:00

I have the following jQuery that sets the content of each (empty) DIV (with

  • 0

I have the following jQuery that sets the content of each (empty) DIV (with unique id’s that start with alpha characters) that has a class = ‘editable’. I’m using an MVC4 api controller with a GET method to return a string of HTML.

For some reason the loadStuff function below is outputting quotes that can be seen in the web page before and after the returned content. This happens on every DIV and is definitely not returned in the api controller method returning a string.

$(document).ready(function () {
     $('.editable').each(function () {
          var curId = this.id.replace('content', '');
          loadStuff(curId, this.id);
     })
});

function loadStuff(curId, targetId) {
     $('#' + targetId).load('api/briefingItem/' + curId);
}

However when I replace the loadStuff function with the code below and use .appendTo the quotes don’t appear.

function loadStuff(curId, targetId) {
     $.getJSON("api/briefingItem/" + curId,
          function (data) {
               $(data).appendTo('#' + targetId);
          })          
}

This seems overkill for returning a simple string and documentation suggests. Can anyone explain this unusual behaviour?

API Controller

// GET api/BriefingItem/5
public string Get(int id)
{
    string newVal = string.Empty;

    switch (id)
    {
        case 12:
            newVal = @"<p>this is some example text that you can edit inside the <strong>tinymce editor</strong>.</p><p>nam nisi elit, cursus in rhoncus sit amet, pulvinar laoreet leo. nam sed lectus quam, ut sagittis tellus. quisque dignissim mauris a augue rutrum tempor. donec vitae purus nec massa vestibulum ornare sit amet id tellus. nunc quam mauris, fermentum nec lacinia eget, sollicitudin nec ante. aliquam molestie volutpat dapibus. nunc interdum viverra sodales. morbi laoreet pulvinar gravida. quisque ut turpis sagittis nunc accumsan vehicula. duis elementum congue ultrices. cras faucibus feugiat arcu quis lacinia. in hac habitasse platea dictumst. pellentesque fermentum magna sit amet tellus varius ullamcorper. vestibulum at urna augue, eget varius neque. fusce facilisis venenatis dapibus. integer non sem at arcu euismod tempor nec sed nisl. morbi ultricies, mauris ut ultricies adipiscing, felis odio condimentum massa, et luctus est nunc nec eros.</p>";
            break;
        case 13:
            newVal = @"<p>look up $(content).load() jquery method and the callback function.</p>";
            break;
        default:
            newVal =  @"<h3>click to enter content.</h3>";
            break;
    }

    return newVal;
}
  • 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-11T22:12:25+00:00Added an answer on June 11, 2026 at 10:12 pm

    The actual response from the Web API is a string which is enclosed in double quotes.

    The difference between the $.getJSON() and .load() methods is that the $.getJSON method assumes that the response is a JSON encoded string => it strips the double quotes wheres .load assumes HTML and doesn’t do any processing on the result.

    So you could have your Web API controller action return a text/html instead of application/json encoded request:

    public HttpResponseMessage Get(int id)
    {
        string newVal = string.Empty;
    
        switch (id)
        {
            case 12:
                newVal = @"<p>this is some example text that you can edit inside the <strong>tinymce editor</strong>.</p><p>nam nisi elit, cursus in rhoncus sit amet, pulvinar laoreet leo. nam sed lectus quam, ut sagittis tellus. quisque dignissim mauris a augue rutrum tempor. donec vitae purus nec massa vestibulum ornare sit amet id tellus. nunc quam mauris, fermentum nec lacinia eget, sollicitudin nec ante. aliquam molestie volutpat dapibus. nunc interdum viverra sodales. morbi laoreet pulvinar gravida. quisque ut turpis sagittis nunc accumsan vehicula. duis elementum congue ultrices. cras faucibus feugiat arcu quis lacinia. in hac habitasse platea dictumst. pellentesque fermentum magna sit amet tellus varius ullamcorper. vestibulum at urna augue, eget varius neque. fusce facilisis venenatis dapibus. integer non sem at arcu euismod tempor nec sed nisl. morbi ultricies, mauris ut ultricies adipiscing, felis odio condimentum massa, et luctus est nunc nec eros.</p>";
                break;
            case 13:
                newVal = @"<p>look up $(content).load() jquery method and the callback function.</p>";
                break;
            default:
                newVal =  @"<h3>click to enter content.</h3>";
                break;
        }
    
        var response = Request.CreateResponse(HttpStatusCode.OK);
        response.Content = new StringContent(newVal, Encoding.UTF8, "text/html");
        return response;
    }
    

    Now you could use the .load() method but not the $.getJSON method.

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

Sidebar

Related Questions

I am using the jquery datatable plugin. I have the following code that sets
Hi I have the following jQuery code that splits some content after the second
I have the following jquery that I wrote: $(document).ready(function(){ $('div.contentTxtBox#home').addClass('current').show(); $('a.menu').click(function() { $('div.contentTxtBox.current').hide(slide, {
I have the following jQuery code that detects if a user has clicked a
I have the following Jquery that returns values from a dialog Box and fills
I have the following jquery function that submits to an iframe. The message sent
I have the following JavaScript/jQuery code that starts the listener that highlights the DOM
I have the following block of jQuery code that I'm using to copy some
I have the following jQuery calls chain: $(someSelector).nextUntil(.specialClass).addClass(classBasedSomeSelectorObject) I need to addClass that's value
I have the following scenario jQuery('#content').fadeOut('slow',function(){ jQuery('#content').load(detail.php?product=+imgID+&category=+cat); jQuery('#content').fadeIn('fast'); }); My problem however is that

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.