0

I am using jQuery with jqgrid and I wanted to use few value from the edit results. The result of the edit is a multidimensional array. For some reason I can only alert up to the second child, the result goes undefined if i go any further.

The main array variable is postdata and if i have to iterate this using jQuery's .each() function, I get these:

(item : value) format. the number is for the order of appearance

1 readyState : 4

2 setRequestHeader : function({....}) 
..
..
..
21 responseText : Array (
        [id] => 364
        [oper] => edit
        [note] => editing
        [client] => raha
   )

My intention is to get the value of id but if i have to alert the array outside the .each() function using this:

alert(postdata['responseText']['id'])

The alert result is undefined. If I removed the ['id'], it shows the entire responseText array (same with number 21).

How do I accomplish this task? many thanks.

SOLVED! Thanks to @Felix for the idea and to @Jasper for suggesting about the console.log.

The result of the jqGrid responseText is in double quotes, which makes it a string. I managed to solve this using the .split() function, two splits to be exact. First splitting it by '\n' and then by '=>'. I finally got what I wanted.

Thanks all

3
  • 1
    Could you check the type of postdata['responseText']? I suspect it is a string, as that Array stuff looks like what php's print_r outputs when given an array. Commented Nov 28, 2011 at 20:54
  • i ran a console.log(postdata), as suggested by @Jasper, and the result is exactly the same as above. Commented Nov 28, 2011 at 21:53
  • I think you're right in saying that it's a string because it shows in double qoutation in firebug console. Is it possible to select an item from this? thanks. Commented Nov 28, 2011 at 22:04

1 Answer 1

1

If you can log the postdata variable and post the whole variable it would be much easier to give you advice (console.log(postdata);). That being said perhaps responseText is an array of objects in which case you would need to access its data like this:

alert(postdata['responseText'][0]['id']);
Sign up to request clarification or add additional context in comments.

1 Comment

the result of the console.log(postdata) is the same, apart from a double qoute that holds the Array for responseText. The alert renders undefined.

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.