views:

2801

answers:

4

Executing that:

$.post(
"/url/to/method",
{ },
function(data){
    var obj2 = eval("("+$(data).children()+")");
    // OR var obj = $.evalJSON($($(data).children())); // Jquery-json
    $body = $("#AAA");
    $body.html(obj.fied);
},
 "xml"
);

while turn into a "missing ] after element list" (at row 5 or 6) error in firebug. The JSON output from method has been validated with jsonlint.com/

Probably is obvious but please I'm newbie around AJAX/JSON. Thanks

+3  A: 

Use the JSON.parse method, or be sure to include a space next to your parens before passing it to eval...

eval(" (" + data + ") ");
Josh Stodola
Using eval with spaces is still a no go (Same error). Using JSON.parse i go a strange error: text.replace is not a function, json2.js:445
Please post the JSON. If it contains sensitive info, re-create the error using dummy data. There is obviously something wrong with it.
Josh Stodola
A: 

Are you writing this in the .NET 2.0? If so try constructing your data into a query string rather than passing a JSON object.

Example: var1=alma&var2=user

Where "var1" and "var2" are the names of the parameters that your webmethod expects. Pass this using the post.. Data: {querystring} I ran into issues when passing JSON to webservice in 2.0.

Good Luck

Nick
+4  A: 

What is probably happening is that your $.post call is returning a JSON object already. jQuery will try to detect JSON automatically and parse it for you. When you call eval on a JSON object like this, you see this error. Sneaky! Just use the data object as is.

adum
I had this issue, now using just the object I'm able to access to the JSON's members. Thanks.
Felix Guerrero
I also was able to fix my issue with this answer. Thanks.
mVChr
A: 

Sneaky! Just use the data object as is.

Worked for me ..Thanks adum..

pravin