views:

102

answers:

1

Hi,

I am working on a facebook page in which i have used ajax & response is returned in json format. I have encoded the string in php. Now i want to decode that string in javascript.

foreach($feedbackdetails as $feedbackdetail)
{
 $str.= '<div class="tweet">
<img style="cursor:pointer;" id="imgVoteUp" src="http://myserver/facebook/vote_up.gif" alt="Vote Up" title="Vote Up" onclick="saveVote('.$feedbackdetail[pk_feedbackid].',1)"  /> : '.$feedbackdetail[upvotecount].'
<img style="cursor:pointer;" id="imgVoteDown" src="http://myserver/facebook/vote_down.gif" alt="Vote Down" title="Vote Down" onclick="saveVote('.$feedbackdetail[pk_feedbackid].',0)" /> : '.$feedbackdetail[downvotecount].'
<p class="'.$pclass.'">'.$feedbackdetail[title].' by '.$feedbackdetail[name].'<br>'.$feedbackdetail[description].'</p></div>';
}
$str=urlencode($str);
echo '{"fbml_test":"'.$str.'"}';

Javascript Function:

function saveVote(id,type,class) {

contentdiv='div_'+id;
processdiv='processdiv_'+id;
document.getElementById(processdiv).setInnerXHTML('<span id="caric"><center><img src="http://static.ak.fbcdn.net/rsrc.php/z5R48/hash/ejut8v2y.gif" /></center></span>');
posturl='http://myserver/facebook/vote.php';
if(class==0)
{
    class='firstmessage';   
}
else
{
    class='message';
}
var queryString = "?id="+id+"&type="+type+"&pclass="+class;
posturl = posturl +queryString;
ajax = new Ajax();
ajax.responseType = Ajax.JSON;
ajax.requireLogin = true;
ajax.ondone = function(data) {
    document.getElementById('caric').setStyle('display','none'); 
    //new Dialog().showMessage('Dialog',data);
    if(data.error)
    {
    new Dialog().showMessage('Dialog',data.error);
    }
    if(data.fbml_test)
    {
    document.getElementById(contentdiv).setInnerFBML(data));
    }
    //div_id.setInnerFBML(data);    
}
ajax.post(posturl);

}

Right now i am getting encoded string how can i change it?

Please help me on this

Thanks

Pankaj

A: 

If the string is urlencoded then javascript has encodeURI and decodeURI functions:

decodeURI(urlencoded_string);
slebetman
valya
The encoding was done by the OP in PHP.
slebetman