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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:42:53+00:00 2026-06-10T23:42:53+00:00

i have this code function, im trying to get an html and appendchild a

  • 0

i have this code function, im trying to get an html and appendchild a li into the html received in msg but not working

function handleFileSelect(evt)
{
    var files = evt.target.files;
    $('#visor_zone').fadeOut(600);
    $('#visor_zone').empty();
    $.ajax(
    {
        url: '/home/visor_publicacion',
    }).done(function(msg)
        {
            var html=msg;
            for (var i = 0, f; f = files[i]; i++)
            {
                if (!f.type.match('image.*')) 
                {
                    continue;
                }
                var reader = new FileReader();
                reader.onload = (function(theFile) {
                    return function(e) {
                        var li = document.createElement('li');
                        li.innerHTML = ['<li><a><img ref="', e.target.result,'" src="', e.target.result,'"/></a><span>esta es la foto agregada</span></li>'].join('');
                        //li.innerHTML = ['Nombre: ', escape(theFile.name), ' || Tamanio: ', escape(theFile.size), ' bytes || type: ', escape(theFile.type), '<br /><img class="thumb" src="', e.target.result,'" title="', escape(theFile.name), '"/><br />'].join('');
                        html.getElementById('pikame').appendChild(li);
                    };
                })(f);
                reader.readAsDataURL(f);
            }
            $('#visor_zone').fadeIn(600,function()
                {
                    $('#visor_zone').html(html);
                    $("#pikame").PikaChoose({autoPlay:false});
                });

        });
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);

it doesnt work but this next work why is that what is the diference between thoses

function handleFileSelect(evt)
{
    var files = evt.target.files;
    $('#visor_zone').fadeOut(600);
    $('#visor_zone').empty();
    $.ajax(
    {
        url: '/home/visor_publicacion',
    }).done(function(msg)
        {
            $('#visor_zone').html(msg);
            for (var i = 0, f; f = files[i]; i++)
            {
                if (!f.type.match('image.*')) 
                {
                    continue;
                }
                var reader = new FileReader();
                reader.onload = (function(theFile) {
                    return function(e) {
                        var li = document.createElement('li');
                        li.innerHTML = ['<li><a><img ref="', e.target.result,'" src="', e.target.result,'"/></a><span>esta es la foto agregada</span></li>'].join('');
                        //li.innerHTML = ['Nombre: ', escape(theFile.name), ' || Tamanio: ', escape(theFile.size), ' bytes || type: ', escape(theFile.type), '<br /><img class="thumb" src="', e.target.result,'" title="', escape(theFile.name), '"/><br />'].join('');
                        document.getElementById('pikame').appendChild(li);
                    };
                })(f);
                reader.readAsDataURL(f);
            }
            $('#visor_zone').fadeIn(600,function()
                {
                    $("#pikame").PikaChoose({autoPlay:false});
                });

        });
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
  • 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-10T23:42:55+00:00Added an answer on June 10, 2026 at 11:42 pm

    var html=msg;

    The reason of failure of first one is calling javascript on methods on string which requires to be executed on DOM

    var html=msg; has html in string not dom so you can not execute javascript method on it which work on DOM

    $('#visor_zone').html(msg);
    

    The reason for the success of second one is the above statement, recevived msg string is assigned to dom as html of visor_zone element, which makes it possible for javascript methods to work on received messsage html (which became part of DOM)

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

Sidebar

Related Questions

i have this code $(function() { $('#ans_vote a span').click(function(){alert('working');return false;});}); and this html <div
I'm trying to get JSON data to turn it into html but the JSON
I am trying to get the following to work. I have this code in
I have been trying to get this code to work for a while now
I've been trying to get this right but any of the code i try
Trying to get this code to work but the error I am getting in
I am trying to get this code to show only fields that have values,
I have been trying for this but no success. I am using PHP, HTML,
I have this code: function Keyboard() { this.log = $('#log')[0]; this.pressedKeys = []; this.bindUpKeys
I have this code: function submitTwice(f){ f.action = 'http://mydomain.com/threevideopage.php'; f.target='name'; f.submit(); } I left

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.