Wednesday, 15 September 2010

php - Send a boolean value in jQuery ajax data -



php - Send a boolean value in jQuery ajax data -

i'm sending info in ajax call. 1 of values boolean set false. evaluated true in php script called ajax. ideas?

$.ajax({ type: "post", data: {photo_id: photo_id, vote: 1, undo_vote: false}, // of import boolean! url: "../../build/ajaxes/vote.php", success: function(data){ console.log(data); } });

in vote.php, script called in above ajax, check boolean value:

if ($_post['undo_vote'] == true) { photo::undo_vote($_post['photo_id']); } else { photo::vote($_post['photo_id'], $_post['vote']); }

but $_post['undo_vote'] == true status met.

a post text, , text evaluate true in php. quick prepare send 0 instead of false. set quotes around true in php.

if ($_post['undo_vote'] == "true") { photo::undo_vote($_post['photo_id']); } else { photo::vote($_post['photo_id'], $_post['vote']); }

then can pass in true/false text. if that's prefer.

php jquery ajax json boolean

No comments:

Post a Comment