0

Looking at this question, you can access a JSON that has this format,

{
    "d": [
        {
            "col1": "col 1 data 1",
            "col2": "col 2 data 1"
        },
        {
            "col1": "col 1 data 2",
            "col2": "col 1 data 2"
        }
    ]
}

and get data via data.d[1].col1 (or col2, or other column names)

But what if I want to create a function and pass parameter to jsonColumn, an argument that will contian my desired column? For example:

Function ajaxJSONgetter(JSONfile, htmlElement, **jsonColumn**)
$.ajax(JSONfile,
            {
                dataType: 'json', //this will always be thru jSON
                success: function (data, status, xhr) { 

                    swal(data.d[0].**jsonColumn**);

                },
                error: function (jqXhr, textStatus, errorMessage) {

                }

            });

how do I pass "col1" to jsonColumn??

Community
  • 1
  • 1
Malcolm Salvador
  • 1,476
  • 2
  • 21
  • 40

0 Answers0