Passing POST data from Javascript(jquery) to php problems? -
i been trying passing value:
// content submit php others string here. , link: http://www.youtube.com/watch?v=cuugkj2i1xc&feature=rec-lgout-exp_fresh+div-1r-2-hm
to php page, , insert database. here current code:
... // javascript var content = $("#mcontent").val(); $.ajax({ url : '<?php echo path; ?>functions/save.php', type: 'post', data: 'id=<?php echo $_get['id']; ?>&content=' + content + '&action=save&val=<?php echo md5("secr3t" . $_session['userid_id']); ?>', datatype: 'json', success: function(response) { if (response.status == 'success') { alert(response.message); } else { alert(response.message); } } });
no errors actually, in database, saved is:
others string here. , link: http://www.youtube.com/watch?v=cuugkj2i1xc
i guess know whats problem, problem the:
http://www.youtube.com/watch?v=cuugkj2i1xc&feature=rec-lgout-exp_fresh+div-1r-2-hm
i think takes "&feature=" post data. have tried:
adding slash before ampersand (http://phpjs.org/functions/addslashes:303)
using javascript html encode/decode function (found somewhere on internet also)
but both not work. have others way?
edit:
do foresee others problem might occurs? content type/write user. meaning that, user can type/write anything. on backhand, did others checking though, including "mysql_real_escape_string"
a nice thing jquery data parameter can take js object, don't need try build query string manually.
<?php $data = array("id" => $_get['id'], "action" => "save", "val" => md5("secr3t",$_session['userid_id']) ); $json_data = encode_json($data); $json_data = str_ireplace($json_data, '</script>', '<\/script>'); echo "var data = $json_data;"; ?> data.content = content; $.ajax({ url : '<?php echo path; ?>functions/save.php', type: 'post', data: data, datatype: 'json',
Comments
Post a Comment