J'ai des problèmes pour envoyer un tableau JSON jQuery via Ajax à un script PHP. Quel est le problème ici:Envoyer JSON jQuery Ajax à PHP et retour
var tee = $('#voting_image img').attr('id');
var vote = 1;
var thing = {tee: tee, vote: vote};
var encoded = $.toJSON(thing);
$.ajax({
url: '/vote_save.php',
type: 'POST',
dataType: 'json',
data: 'vote='+encoded,
success: function(data)
{
var back = $.evalJSON(data).name;
$('#voting_hint_name').html(back);
$('#voting_buttons').html('<div id="voting_buttons"><a href="#" id="vote_yes">PRINT IT</a><a href="#" id="vote_no">DON\'T PRINT IT</a></div>');
},
error:function()
{
$('#voting_buttons').html('<div id="voting_buttons"><a href="#" id="vote_yes">PRINT IT</a><a href="#" id="vote_no">DON\'T PRINT IT</a></div>');
alert("There was a problem, your vote was not saved, please try again!");
}
});
C'est le PHP
if (isset($_POST['vote'])&&isset($_SESSION['user']))
{
$tee_data = json_decode($_POST['vote']);
$the_tee = $tee_data['tee'];
$responce = array('name'=> 'Alex Wow', 'test'=> '1');
echo json_encode($responce);
}
else {
echo "error";
}
L'erreur que je reçois dans Firebug est:
Error: JSON.parse
désolé oublié de mentionner que j'utilise un plugin json pour jQuery – Titan
@Alex Crooks - Quel plugin serait-ce? – Ender
http://code.google.com/p/jquery-json/ mais je ne l'utilise que dans l'exemple car j'ai du mal à faire en sorte que cela fonctionne de manière différente – Titan