Tom S
Tom S

Reputation: 174

Check whether data returned from php via ajax is empty

I have tried (data = "") and various others but none seem to work.

$.ajax({
    url: "includes/peopleGoingList.php",
    type: "POST",
    dataType: "html",
    data: {"ID": eventID},
    success: function(data){
    console.log(data);

    if (data.length === 0) {
        $("#dialog-attendees").html("<p>No one is going.. :[</p>");
    } else {
        $("#dialog-attendees").html(data);
    }
});

Upvotes: 0

Views: 75

Answers (1)

Musa
Musa

Reputation: 97672

There are probably arbitrary white space in your output, try trimming it

if ($.trim(data) == '') {

Upvotes: 3

Related Questions