18

I keep getting an error when I run the javascript below in Firebug. I've tried changing multiple things and it still outputs the error. I am working with an api to retrieve information from the XML and then output it onto the screen but I keep getting an object error. Can someone see why?? Any help is appreciated!

$(document).ready(function() {

    $('#searchbtn').bind('click' || 'enter',function(e) {
        if ($.trim($('#searchBox').val()) !== '') {
            $('#videos').append('<img src="img/loading.gif" alt="loading" class="loading" />');
            getVideos(e);
        }
    });
});

function getVideos(e) {
    e.preventDefault();
    var text = 'text='+$('#searchBox').val();
    $.ajax({
        url: 'getVideos.php',
        dataType: 'xml',
        type: 'POST',
        data: text,
        success: function(data) {                               
            $('#videos').append("<h1>The following events match your search!</h1>");

            var xmlString = data;

            if ($(xmlString).find('feed').children('entry').length == 0) {
                $('#videos').append('<p class="noResults">Sorry, no results for you! Try searching again!</p>');
            } else {
                var videoTitle = [];

                $(xmlString).find('title').each(function() 
                { 
                videoTitle.push($(this).text()) });

                $('#videos').append('<ul>');

                $(xmlString).find('entry').each(function(i) {
                    if (i == '40') {
                        return(false);
                    }
                    var vidInfo = '';
                    vidInfo += "<p>"+videoTitle[i]+"</p>";
                    $('#videos ul').append('<li>'+vidInfo+'</li>');
                });
            }
        },
        error: function(data) {
                console.log('Error: ' + data);
        }

    })
};
2
  • can you please put your exact error ? Commented Apr 14, 2012 at 18:52
  • As Chuck replied, you are adding a string Error: to your data object. Commented Apr 14, 2012 at 18:57

1 Answer 1

26

When you append an object to a string, it gets its toString method called, which for a plain object just gives the infamous "[object Object]". To log an object, you should just pass it straight into the console.log function as an argument, like so:

console.log('Error:', data);
Sign up to request clarification or add additional context in comments.

1 Comment

@LE12: You should replace the line that reads console.log('Error: ' + data); with that code, yes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.