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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:38:20+00:00 2026-06-15T13:38:20+00:00

I have a working Ajax utilized by JQuery and am changing what is listed

  • 0

I have a working Ajax utilized by JQuery and am changing what is listed on the page via a JSON response.

It works perfectly with text, however, now I plan to use the same code but have a video displayed instead where for example the mpg is displayed. However, it simply displays the text of the embed code from youtube instead.

Html page which gets JSON response:

 $(document).ready(function()
    {
            $("#submitbutton").click(function()
            {
                    $.ajax(
                    {
                            url: "https://example.com/jsonServer.php",
                            type: "GET",
                            dataType: "jsonp",
                            jsonp: "callback",
                            data: { carselection: $("#carselection").val()},
                            success: function(data)
                            {
                                    if(data.name == "error")
                                    {
                                            $("#outputcarname").text("There is no such car available"),
                                            $("#price").text(" "),
                                            $("#mpg").text(" ");
                                    }
                                    else
                                    {
                                            $("#outputcarname").text(data.name),
                                            $("#price").text(data.price),
                                            $("#mpg").text(data.mpg);
                                    }
                            },
                            error: function()
                            {
                                    $("#outputcarname").text("There is a problem with the server"),
                                    $("#price").text(" "),
                                    $("#mpg").text(" ");
                            }
                    });
            return false;


 });
});
</script>

JSON Server:

*note that I have replaced one of the mpg’s with embed code straight from youtube, and again, this embed code displays exactly as is in the mpg area.

  <?php

    $cars = array('Maxima' => array('price' => '$32,780', 'mpg' => '24'),
                  'Prius' => array('price' => '$25,565', 'mpg' => '49'),
                  'Element' => array('price' => '$22,075', 'mpg' => '<iframe width="560" height="315" src="http://www.youtube.com/embed/enXTiYWQl-0" frameborder="0" allowfullscreen></iframe>'));

    if(array_key_exists($_GET['carselection'], $cars))
    {
            $carname = $_GET['carselection'];
            $results = array('name' => $carname, 'price' => $cars[$carname]['price'], 'mpg' => $cars[$carname]['mpg']);
    }
    else
    {
            $results = array('name' => 'error');
    }

    $callback = htmlentities($_GET['callback'], ENT_QUOTES);
    print $callback . '(' . json_encode($results) . ')';
    ?>

My hope was that the browser would accept the tags and display the video obviously, however I would guess the jquery.text is keeping it as truly text. Perhaps there is another function I am unaware of that I should be using?

  • 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-15T13:38:21+00:00Added an answer on June 15, 2026 at 1:38 pm

    Change this:

    $("#mpg").text(data.mpg);
    

    to:

    $("#mpg").html(data.mpg);
    

    .text() treats the string as a text.

    .html() treats the string as html

    jQuery: text() vs html()?

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

Sidebar

Related Questions

I am working on parsing some xml via jquery ajax. I have things working
I am working on a filter functionality using ajax/jquery and php/mysql.I have two sets
I am very new to javascript and ajax/jquery and have been working on trying
I think this is quite simple. I have a working AJAX Jquery script which
I have my Ajax working, builtin Rails javascript, with the submit button. However, I
Through jQuery and the use of an ajax get I have a working model
I have been working with jQuery and AJAX for a few weeks now and
Rails 3 app.... I have the following jQuery which is working: $.ajax({ url: '/navigations/sidenav',
so i have an already working jquery ajax application that i'm trying to create
I have been working on writing a servlet for AJAX/JSON. I want to reference

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.