0

I want to display data in the value field of dictionary using Ajax. I know the format to display, but stuck in displaying one of the fields. Code is here :

$.each(result, function(index, element) {
      alert(element.Place);
      alert(element.Unique Name);
   });

element.Unique Name doesn't work as there is a space in between( It is Unique Name not UniqueName). Could you guys help me out displaying this?

12
  • 2
    I'm not sure whether it work, try element[Unique Name] Commented Jul 14, 2015 at 6:17
  • I had tried it before and it doesn't work :( @Gopinath Shiva Commented Jul 14, 2015 at 6:21
  • can u show me the html part, to check for other possibilities... Commented Jul 14, 2015 at 6:22
  • In short, I have a table with some 50 rows. I want to append the rows with the values I get from Ajax call to the already existing table @Gopinath Shiva Commented Jul 14, 2015 at 6:27
  • in that case you can use .text() or .val() on the selector element? Commented Jul 14, 2015 at 6:31

1 Answer 1

1

Fiddle for your answer

    var data = {
    "employees": [{
        "firstName": "John",
        "Unique Name": "Doe"
    }, {
        "firstName": "Anna",
        "Unique Name": "Smith"
    }, {
        "firstName": "Peter",
        "Unique Name": "Jones"
    }]
};

$.each(data, function (index, element) {
    alert(index);
    $.each(element, function (inde, data1) {
        alert(inde);
        alert(data1.firstName);
        alert(data1['Unique Name']);
    });
});

I think it may meet your requirements. plz let me know if works.

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

Comments

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.