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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:54:29+00:00 2026-05-26T20:54:29+00:00

I have a function that searches a database table via ajax. This is the

  • 0

I have a function that searches a database table via ajax.
This is the function

function find_file(query)
    {
        var xtoken = $("input[name='xtoken']").val();
        var uri = site_url+'admin/media/search';
        //make request to controller method
        $.get(uri,{ 'xtoken' : xtoken,'query':query },
        function(data) {
            var dataLength = data.length;
            if(dataLength < 1)
            {
                $.gritter.add({title:'Notice',text:'No matching results',sticky:false,time:'3000'});
            }else {
                var dataGrid = $('#files table tbody');
                dataGrid.html('');
                $.each(data,function(index,file)
                {
                    var media_thumbnail ="";
                    if((file.file_type == "image/jpeg") || (file.file_type == "image/png") || (file.file_type == "image/png"))
                    {
                        media_thumbnail = '<img src="'+file.file_path+'" height="60" width="46" />';
                    }
                    if((file.file_type == "audio/mp3") || (file.file_type == "audio/wma"))
                    {
                        media_thumbnail = '<img src="'+site_url+'assets/admin/audio.png" />';
                    }
                    dataGrid.append(
                        '<tr class="files" id="'+file.file_id+'">'+
                            '<td><input id="file_id" type="checkbox" name="file_id[]" value="'+file.file_id+'" /></td>'+
                            '<td>'+
                                '<div class="media_preview">'+media_thumbail+'</div>'+
                                '<a href="'+site_url+'admin/media/editmedia/'+file.file_id+'">'+file.file_name+'</a>'+
                            '</td>'+
                             '<td>'+file.file_type+'</td>'+
                             '<td>'+file.author+'</td>'+
                             '<td>'+file.upload_date+'</td>'+
                        '</tr>'
                    );
                });
            }
        });
    }

When the code executes, I get an error saying var media_thumbnail is undefined, even after I declare the variable as empty ” var media_thumbnail = ""; ”
Am setting the value of the var media_thumbail after testing an object from the JSON return of the ajax call.
See this part of the code

var media_thumbnail ="";
                    if((file.file_type == "image/jpeg") || (file.file_type == "image/png") || (file.file_type == "image/png"))
                    {
                        media_thumbnail = '<img src="'+file.file_path+'" height="60" width="46" />';
                    }
                    if((file.file_type == "audio/mp3") || (file.file_type == "audio/wma"))
                    {
                        media_thumbnail = '<img src="'+site_url+'assets/admin/audio.png" />';
                    }

What is wrong with my function?

  • 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-26T20:54:30+00:00Added an answer on May 26, 2026 at 8:54 pm

    You misspelled the variable reference:

    '<div class="media_preview">'+media_thumbail+'</div>'+
                                             ^ missing 'n'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a search form that searches a table in my database. The table
I have a Flex application that calls a function which searches a large document
I have a function that looks like this class NSNode { function insertAfter(NSNode $node)
I have a function that searches for a string inside a text file. I
So I have a jquery autocomplete on a testbox that searches the database for
I have a query in my controller which searches for the term/keyword that is
I have a gridview that displays the contents of a database table, using an
I have following challenge: Implement a function that searches for a null point of
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in

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.