1

I'm working on mvc5 I want to bind data to div using .html(data)

.done(function (data) {
    var result = $.parseJSON(data);
    $("mydata").html(result);
});
<div id="mydata"></div>

Object data has values like following.

enter image description here

How do I bind values into $("mydata")?

I tried like above but it does not work.

1 Answer 1

2

Assuming that the response is coming back in JSON format then jQuery will have already deserialised it to an object for you. Calling parseJSON on the resulting object will cause an error.

Also, you are trying to set an object as the HTML value of an element which will result in the text [Object object] being shown. Instead you need to access the properties of that object.

Try this:

.done(function (data) {
    $("#mydata").html(data[0].Address); // will show 'pune'
});

Also note that your selector is missing the # - assuming that you are selecting by id.

Sign up to request clarification or add additional context in comments.

5 Comments

jQuery ID selector... $("#mydata")
@Edgar good catch. I assume that's just a typo the OP made in the question.
@RoryMcCrossan Watch shows correct value but not displayed in div :O strange why so ? not binding pune value to given div
@anish as Edgar says, you selector should be $('#mydata') - assuming you're selecting by id.
Damn it ! small mistake how can I do so hurry :( thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.