[英]Encoded HTML string incorrectly decoded in CodeIgniter
I post data containing an html string as well as some other data from JavaScript to the PHP (Codeigniter) server w/ AJAX & JSON. 我将包含html字符串以及其他一些JavaScript数据的数据发布到带有AJAX和JSON的PHP(Codeigniter)服务器。
The HTML string contains an image tag w/ some style data. HTML字符串包含带有某些样式数据的图像标签。 On the server, the style info is gone!
在服务器上,样式信息不见了! The rest of the data I post is just fine.
我发布的其余数据都很好。
What should I do to the HTML string to prevent this? 我应该对HTML字符串采取什么措施来防止这种情况?
JavaScript side: JavaScript方面:
my_html='<p><img alt="" src="/ckfinder/userfiles/images/ferns.jpg" style="width: 200px; height: 133px;" /></p>';
my_count=1;
This is the data that gets posted in the AJAX call: 这是在AJAX调用中发布的数据:
form_data='my_html='+encodeURIComponent(my_html)+'&my_count='+my_count;
On the server: 在服务器上:
$html_str=$this->input->post('my_html');
$this->chromephp->log($html_str);
And this is what it prints: 这是它打印的内容:
<p><img alt="" src="/ckfinder/userfiles/images/ferns.jpg" /></p>
EDIT - 1/24/18 After more investigation, it seems to be a decoding issue or the way I'm reading the value in Codeigniter (v 2). 编辑-1/24/18经过更多调查,这似乎是解码问题或我在Codeigniter(v 2)中读取值的方式。 Nothing to do with the fact it's an image tag.
它与图像标签无关。
Here's what I've figured out - 这是我想出来的-
Javascript: Javascript:
var hstr ='<p style="color:red;">Hello</p>';
After encodeURIComponent(), encoded string submitted as form data: 在encodeURIComponent()之后,将编码后的字符串作为表单数据提交:
%3Cp%20style%3D%22color%3Ared%3B%22%3EHello%3C%2Fp%3E
But, in the server: 但是,在服务器中:
The (URIencoded string being submitted as form data over AJAX: $html_str=$this->input->post('hstr'); $this->chromephp->log($html_str); (URI编码的字符串通过AJAX作为表单数据提交:$ html_str = $ this-> input-> post('hstr'); $ this-> chromephp-> log($ html_str);
yields: 产量:
<p >Hello</p>
On the server if I urldecode() the encoded string directly, 在服务器上,如果我直接urldecode()编码的字符串,
$xx=urldecode('%3Cp%20style%3D%22color%3Ared%3B%22%3EHello%3C%2Fp%3E');
$this->chromephp->log($xx);
yields: 产量:
<p style="color:red;">Hello</p>
So is it that Codeigniter (v2) decodes it when I use input->post()? 那么,当我使用input-> post()时,Codeigniter(v2)会对它进行解码吗? Is there a way to get the raw undecoded string?
有没有办法获取未解码的原始字符串?
Any suggestions? 有什么建议么?
Help! 救命! Please!
请!
Mmiz 米米兹
尝试
form_data='my_html='+encodeURI(my_html)+'&my_count='+my_count;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.