Blabla
Blabla

Reputation: 377

Detect Empty result in JS

I have an ActionResult which return PartialView() or new EmptyResult(), How to detect in JS callback function if returned data is EmptyResullt()? I have tried many ways, i.e. compare with null or with undefined but no results. console.log(data) shows blank space. Any tips and tricks? :)

"more code":

Controller:

    public ActionResult Checkif(int d)
    {
        if (d == 2) return new EmptyResult();
        else return PartialView();
    }

Js function:

function sth ()
{
    $.get('/home/Checkif/', {d: 2}, function(data){
        if(data === null) //<---- this does not work
        {
            //then sth;
        }
    })
}

Upvotes: 2

Views: 2197

Answers (1)

vijayst
vijayst

Reputation: 21856

Usually, checking for if (data) { // do something } will work.

To specifically check for empty string, using data === '' should work.

Upvotes: 2

Related Questions