Click here to Skip to main content
15,887,848 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I am getting this error in firebug console panel: TypeError: e is null

As you will see in my code bellow, I ma trying to catch that error but it is not working, it is displaying that error above.

This is my code:

JavaScript
$.ajax({
    type: "POST",
    url: "Rooms.aspx/GetAvailRoom",
    data: '{ Checkin: "' + $checkinDate +
            '", Checkout: "' + $checkoutDate + '" }',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (response) {
    var rooms = response.d;
    alert(rooms);
    var html = '';

    if ($.isEmptyObject(rooms)) {
        alert("Room is not Available!")
        var $showError = $('#showError').show().text('We are sorry, there are no rooms available for the dates you have requested.');
        var $showContact = $('#showContact').show().html('If your dates are flexible, please speak to a hotel reservation agent at <strong>+250788400000</strong>.');
        $('#divRooms').hide();
        $('#notificationError').append($showError, '<br/>', $showContact)
        $('div.loading').hide();  
    }
    else if ((rooms == 'undefined') && (rooms == null)) {
        alert("Please go back and choose reservation!");
    }
    else {
        $.each(rooms, function (index, item) {
            $RoomId = item.RoomId;
            html += '<div class="row" data-id=' + item.RoomId + '>';
            html += '<div class="col-md-4">';
            
            html += BxSlider(item);
            html += '</div>';
            html += '<div class="col-md-4">';
            html += '<h3 class="roomname success">' + item.RoomName + '</h3>';
            html += '<p class="price"><em> ' + item.RoomPrice + '$</em> per night</p>';
            html += '<span class="amentiesHeader">Full Description</span>';
            html += '</div>';
            html += '<div class="col-md-4">';
            html += '<div class="roomextra">';

            if (item.RoomDescription != null) {
                html += '<p class="notetitle">' + item.RoomDescription + '</p>';
            }
    
            html += '<button type="button" class="btn btn-success btn-block book" data-id=' + $RoomId + '>BOOK NOW</button>';
            html += '</div>';
            html += '</div>';
            html += '</div>';
        });
    }
        
        $('#divRooms').html(html);
        $('#divRooms div.row').each(function () {
            var RoomID = $(this).attr("data-id");
            var pagerid = '#pager_' + RoomID;

            $(this).find('ul.bxslider').bxSlider({
                pagerCustom: pagerid,
                controls: false       
            });
        });

        $('div.loading').hide();
        $('.book').on("click", function () {
            alert($RoomId);
            var url = "confirm-your-stay.aspx?checkin=" + encodeURIComponent($checkinDate) + "&checkout=" +
            encodeURIComponent($checkoutDate) + "&roomId=" + encodeURIComponent($RoomId) + "&adults=" + encodeURIComponent($adults)
            + "&children=" + encodeURIComponent($children);
            window.location.href = url;
        });
        
        $("#loading").hide();
    }
});

Can someone tell me what is wrong.
Posted
v3
Comments
Kornfeld Eliyahu Peter 17-Dec-14 1:39am    
Can you tell on which line the error?
El Dev 17-Dec-14 1:59am    
Hi Eliyahu,
The error is coming when there are no available room coming from database.Means the response is null.
I think it is on this line of the ajax response:
var rooms = response.d;
if ($.isEmptyObject(rooms)) {
alert("Room is not Available!")
Kornfeld Eliyahu Peter 17-Dec-14 2:04am    
There is no any e there, so it is not - you have to put your debugger into work!
El Dev 17-Dec-14 2:10am    
Yeah put is coming when there are no rooms(or data) coming from the database.
when there are rooms(data) coming from database.
that e is not appearing.
Put debugger and see where is the issue.

1 solution

It could be because you're not ending this line with a ;
$('#notificationError').append($showError, '<br/>', $showContact)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900