0

So I have an array:

[{'key1':'a', 'key2':'b', 'ProblemKey': {'keyP1': 'c', 'KeyP2':'d'}}, {'key1':'e', 'key2': 'f', 'ProblemKey': ....}}]

When I do the standard $.each loop through the received data (above) from my GET response, all of the keys correspond correctly to their value for each object in the array except the "problemKey"s (because their values are associative arrays and not strings?). Those always come back as Undefined. Is there any way to get the $.ajax method to parse these parts correctly? Or should I return the data as a text document and get some third party plugin that has better parsing abilities than the one that comes with jQuery already?

0

2 Answers 2

1
$.ajax({
            url:'Your post url',
            data : ({
                'elem':elemtopost,

            }),
            method : 'POST',
            dataType: 'json',                 
            success: function(msg){ 

                    for(j=0;j<msg.length;j++){
                            alert(msg[j]['key1']  //accessing the json string
                    }
});
Sign up to request clarification or add additional context in comments.

Comments

1

In your $.ajax call, set the dataType to "json":

$.ajax({
   // other stuff
   dataType: "json"
});

Then in the success function you can access the return value with the dot operator:

var myVal = returnArray[0].ProblemKey.keyP1;

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.