Vahid Akbari
Vahid Akbari

Reputation: 189

jquery post always return false

i use this function for a tag click this work fine and my code return true but data variable is false .why??

  $('#AddProvince').click(function () {
                var url = '@Url.Action("SetProvinceList")';
                var id = $('#Province').val();
                var result=false;
                $.post(url, { PID: id }, function (data) {
                    if (data == true) {
                        var p = "<tr class='tRow'> <td class='tbody'>" + $('#Province         option:selected').text() + "</td></tr>";
                        $('#tblPRovince tr:last').after(p);
                    }
                });               
            });

Upvotes: 1

Views: 215

Answers (2)

Zaheer Ahmed
Zaheer Ahmed

Reputation: 28548

response from call is always a string, you can try:

if(data)

or

if(data === 'true')

Upvotes: 1

Carlo Moretto
Carlo Moretto

Reputation: 365

this is because data is a String, and not a boolean, just use

data == 'true'

Upvotes: 3

Related Questions