user3290332
user3290332

Reputation:

Why doesn't my data get displayed in a textbox?

I am using a jQuery function to get data from the database when I press f12 in my response body I can see the data but its not placing anything in. this is how my function looks like:

function MethodName() {
    $.ajax({
        type: "POST",
        url: "@Url.Action("MethodName", "ControllerName")",
        data: JSON.stringify(),
        contentType: "application/json; charset=utf-8",
        dataType: "json",

        success: function (msg) {
            $('.someText').val(msg);
        }
    });
}

This is my empty div and in here I would like to place my text:

<div class="someText"></div>

Why doesn't it work? I try removing dataType: "json", but nothing appears in my div

Upvotes: 0

Views: 66

Answers (1)

G&#244;T&#244;
G&#244;T&#244;

Reputation: 8053

.val (value) has no meaning for a div.

To set the div inner text:

$('.someText').text(msg);

To set its html content:

$('.someText').html(msg);

Then it depends what you get and how you want to display your stuff. You might want to check JSON.stringify to make sure what your msg looks like ($('.someText').text(JSON.stringify(msg));)

Upvotes: 3

Related Questions