2012-02-22 66 views
-1

我有HTML数据像文本包括图像src.when我警觉使用jquery它工作正常。整个HTML显示在警报box.And然后我想发送完整的HTML数据和文本和JQuery的喜欢的东西的ID使用查询字符串:如何修复这些类型

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

但我需要一个完整的HTML数据,包括文本和id在PHP页面像获取html数据,文本,ID在JQuery警示框中

我尝试使用window.btoa函数(base64编码格式)为HtmlMsgresult。在javascript中执行base64编码格式后,当我尝试在php页面中发送时,它在php页面中没有得到任何打印。

另一件事是,有什么解决办法文字和htmldata(HTML文本和IMG SRC)合并,然后将其完成的base64 encode.And那么它使用的查询字符串在PHP页面发送类似:

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

有没有可能做到这一点?

然后我想在something.php中插入数据库,然后在另一个页面中,我想要使用jquery获取由base64编码的htmldata和文本。然后它被base64_decode函数转换。

但是在文本和htmldata中,如何从数据库表中提取文本,htmltext,htmlimgsrc。

如果你知道有关这些类型的问题,请回复我

我需要你的手

谢谢

回答

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

jQuery将自行申请encodeURIComponent。是的,如果您想自己编码数据,则需要将encodeURIComponent应用于参数的值。阅读以下主题When are you supposed to use escape instead of encodeURI/encodeURIComponent?

ps:你不必在php脚本中做任何事情,数据将被服务器自动解码。在php中访问$_POST['socialprofileid'], $_POST['txtMsg']等等。

+0

我通过parametre在encodeURIComponent方法等变种的param1 = encodeURIComponent方法( “socialprofileid:socialprofileid,txtMsg:MSG,postedHtmlMsg:HtmlMsgresult”); 这些主题有一些问题。 1.html的数据不会来,txtMsg,postedHtmlMsg的img src来2.如何在php页面中个别地分隔param。我只需要使用socialprofileid和textMsg和htmldata文本与img src不同。如果我们在数据库表中插入不同类型的htmldata,如何从数据库表中以特定方式从htmldata中提取文本和img src.How to fix it。我需要你的手。 – 2012-02-22 10:37:04

+0

这是错的。 1)在jQuery的帮助下,你不必这样做。 2)你没有看例子! 'param1 =“socialprofileid =”+ encodeURIComponent(socialprofileid)+“&txtMsg =”+ encodeURIComponent(msg)+ ...'等等。 'htmldata的Img src不来'我不知道你在'HtmlMsgresult'中有什么''如何在php页面中个别地分隔param'我向你展示了你应该如何处理POST数据。运行'phpinfo();'在POST上,你会自己看到它。 – Cheery 2012-02-22 17:14:30

0

在php中,您可以使用$ _POST变量获取发布参数。

<? 
echo $_POST['socialprofileid'], PHP_EOL; 
echo $_POST['txtMsg'], PHP_EOL; 
echo $_POST['postedHtmlMsg'], PHP_EOL; 
?> 
+0

在php页面socialprofileid,txtMsg,postingHtmlMsg未使用window.btoa()从javascript.I回显或未打印。txtMsg中的文本,postingHtmlMsg中的文本和图像以及socialprofileid中的id。我需要从javascript到php页面的socialprofileid,txtMsg,entir postedHtmlMsg(文本和图像两者)。 – 2012-02-22 11:03:13

+0

它可能在jQuery中你的问题在于。 – 2012-02-22 11:12:40