/    Sign up×
Community /Pin to ProfileBookmark

hi all,
I’m trying to send a php array after json_encode($array) to client side via ajax, in the client side, i do a eval(xmlhttprequest.respondeText) but I get this error – “invalid label”

[B]server side(php)[/B]

$encoded_value = json_encode($package_array);
// $package_array of this format
//$package_array[‘1,1,2,15’] = ‘1’
echo($encoded_value); //echoing to ajax

[B]client side(javascript)[/B]

val = ajax_object.responseText;
alert(“val is”+val);
decoded_val = eval(val);
alert(decoded_val);

#ERROR I get is “invalid label {“1,1,C,15″:”1”}

[B]client side(javascript)-try 2[/B]

val = ajax_object.responseText;
alert(“val is”+val);
decoded_val = eval(‘(‘ + val + ‘)’);;
alert(decoded_val);

#with the above eval of responseText I get an object, I don’t know how to read values from this object.

I hope I’m clear with the description of the problem. any help is appreciated.

thanks,
karthik

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorOct 09.2007 — <i>
</i>for(p in decoded_val){
alert(p+' | '+decoded_val[p])
}

See JSON
Copy linkTweet thisAlerts:
@karthik_jscriptauthorOct 09.2007 — thanks kor, problem solved!
×

Success!

Help @karthik_jscript spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...