[英]Not able to get HTML content in PHP via jQuery ajax request
I am using Summernote text editor. 我正在使用Summernote文本编辑器。 I am collecting HTML in following way:
我通过以下方式收集HTML:
var luck = $(".textEditor").code();
my content as of now is as follows : 我现在的内容如下:
<p><br></p>
<img src="http://127.0.0.1/gallery/1/0336dcbab05b9d5ad24f4333c7658a0e.jpeg" style="width: 640px;"><p>Tell your travel story...</p>
I am making following ajax request to send it to PHP 我正在按照ajax请求将其发送到PHP
$.ajax({
dataType : 'json',
async : true,
cache : false,
beforeSend : function(xhr) {
xhr.setRequestHeader("Accept", "application/json");
},
data: {
'luck' : luck
},
type: "POST",
url: "<?php echo base_url(); ?>index.php/travelogue/postBlog",
cache: false,
success: function(data, status, xhr) {
alert(data);
},
error:function(xhr, textStatus, errorThrown) {
alert(xhr); alert(xhr.status); alert(textStatus); alert(errorThrown); alert(xhr.statusText); alert(xhr.responseText); }
});
on PHP side I am getting data in following way (for example sake I am just puting data in txt file( 在PHP方面,我正在通过以下方式获取数据(例如,为了方便起见,我只是将数据放入txt文件中(
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
fwrite($myfile, $_POST["luck"]);
fclose($myfile);
But I get following content. 但是我得到以下内容。 From IMG tag STYLE tag is missing.
IMG标签缺少STYLE标签。
<p><br></p><img src="http://127.0.0.1/gallery/1/0336dcbab05b9d5ad24f4333c7658a0e.jpeg" 640px;"><p>Tell your travel story...</p>
I am not sure how to retrieve data properly? 我不确定如何正确检索数据? Is there problem with ajax request or may be i am not getting data in PHP in correct way?
ajax请求是否存在问题,或者可能是我没有以正确的方式获取PHP中的数据?
Any suggestions would be helpfull.... 任何建议都会有所帮助。
Thanks 谢谢
Take a look at file_get_contents(php://input)
. 看一下
file_get_contents(php://input)
。 Chances are you'll need to uri encode the html string before sending it, to access it in the post array. 您可能需要在发送html字符串之前对其进行uri编码,才能在post数组中对其进行访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.