在javascript中解码通过php编码的字符串

时间:2010-01-05 09:00:30

标签: php javascript

我在facebook页面上工作,其中我使用了ajax&响应以json格式返回。我已经在php中编码了字符串。现在我想在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 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);

}

现在我正在编码字符串如何更改它?

请帮我解决这个问题

由于

的Pankaj

1 个答案:

答案 0 :(得分:0)

如果字符串是urlencoded,则javascript具有encodeURIdecodeURI个函数:

decodeURI(urlencoded_string);