Tippu
Tippu

Reputation: 1261

JQuery AJAX response value to a label

Could you please check and let me know what is the problem in the below code. I have the valid value in the response.d (I checked my adding alert), but when I assign that value to label it is not changing the value in label(lblData).

function LoadPlanBoard() {
    $.ajax({
        type: "POST",
        url: "myplanboard.aspx/WebLoadPlanBoard",
        data: "{flag:'" + 0 + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            $('#<%=lblData.ClientID %>').val(response.d);
        },
        failure: function (response) {
            alert(response);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            var errMessage = "An error occured serving your request. Please try again.";
            if (jqXHR)
                errMessage = $.parseJSON(jqXHR.responseText).Message;
            alert(errMessage);
        }
    });
}

Upvotes: 0

Views: 3692

Answers (2)

kmkemp
kmkemp

Reputation: 1666

Labels in ASP.NET are rendered as span tags I think. I'd try using .html(htmlString).

Upvotes: 1

dMb
dMb

Reputation: 9337

.val() is for reading values of form controls. You should use .text(): http://api.jquery.com/val/

Upvotes: 2

Related Questions