-1

I have html data like text including image src.when I alert using jquery it works fine. Entire html is displayed in alert box.And then I want to send that entire html data and text and something's id using query string of JQuery like:

$.post('something.php','socialprofileid='+socialprofileid+
        '&txtMsg='+msg+'&postedHtmlMsg='+HtmlMsgresult)

But I need that entire html data including text and id in php page like get html data, text, id in JQuery alert box

I try to use window.btoa function(base64 encoded format) for HtmlMsgresult. After doing base64 encoded format in javascript, when I try to send in php page, it doesn't get any print in php page.

Another thing is there any solution Text and htmldata(html text and img src) are combined and then it is done the base64 encode.And then it is send in php page using query string like:

if(txtmsg='') {
  var result=window.btoa(htmldata);
} else {
  var content=text+htmldata;
  var result=window.btoa(content);
}
$.post('something.php','socialprofileid='+socialprofileid+'&result='+result)

Is it possible to do that?

And then I want to insert into database in something.php and then in another page I want to fetch the htmldata and text which are encoded by base64 using jquery. Then it is converted by base64_decode function.

But within text and htmldata, How to extract text , htmltext, htmlimgsrc differently from the database table.

If u know about these type of problems, please reply me

I need your hand

Thank you

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

1
$.post('something.php',
       {socialprofileid:socialprofileid, 
        txtMsg:msg, 
        postedHtmlMsg:HtmlMsgresult});

jQuery will apply encodeURIComponent by itself. And yes, you need encodeURIComponent applied to the values of the parameters if you want to encode the data by yourself. Read the following topic When are you supposed to use escape instead of encodeURI / encodeURIComponent?

ps: you do not have to do anything in the php script, the data will be decoded automatically by the server. Access $_POST['socialprofileid'], $_POST['txtMsg'] and so on in php.

Community
  • 1
  • 1
Cheery
  • 16,063
  • 42
  • 57
  • I pass parametre in encodeURIComponent like var param1=encodeURIComponent("socialprofileid:socialprofileid,txtMsg:msg,postedHtmlMsg:HtmlMsgresult"); There are some questions in these topic. 1.Img src of htmldata not come, txtMsg,postedHtmlMsg of html data come 2.how to divide param indivitually in php page.I need only socialprofileid and textMsg and htmldata text with img src diffrently.3. how to extract text and img src from htmldata from database table in specfic way if we have different types of htmldata that will be inserted in database table.How to fix it. I need ur hand. – Ankan Bhadra Feb 22 '12 at 10:37
  • It is wrong. 1) With the help of jQuery you do not have to do it. 2) You did not look at examples! `param1 = "socialprofileid=" + encodeURIComponent(socialprofileid)+"&txtMsg=" + encodeURIComponent(msg)+...` and so on. `Img src of htmldata not come` I do not know what you have in `HtmlMsgresult`.. `how to divide param indivitually in php page` I showed you how you should deal with POST data. Run `phpinfo();` at POST and you will see it by yourself. – Cheery Feb 22 '12 at 17:14
0

In php, you can get the post parameters with the $_POST variable.

<?
echo $_POST['socialprofileid'], PHP_EOL;
echo $_POST['txtMsg'], PHP_EOL;
echo $_POST['postedHtmlMsg'], PHP_EOL;
?>
Xyz
  • 5,955
  • 5
  • 40
  • 58
  • In php page socialprofileid, txtMsg, postedHtmlMsg not echoed or not printed using window.btoa() from javascript.I have text in txtMsg, text and image in postedHtmlMsg and id in socialprofileid.I need socialprofileid, txtMsg, entir postedHtmlMsg(text and image both) from javascript to php page. – Ankan Bhadra Feb 22 '12 at 11:03
  • The it is likely in jquery your issue lies. – Xyz Feb 22 '12 at 11:12