繁体   English   中英

无法通过jQuery ajax请求获取PHP中的HTML内容

[英]Not able to get HTML content in PHP via jQuery ajax request

我正在使用Summernote文本编辑器。 我通过以下方式收集HTML:

var luck = $(".textEditor").code();

我现在的内容如下:

<p><br></p>
<img src="http://127.0.0.1/gallery/1/0336dcbab05b9d5ad24f4333c7658a0e.jpeg" style="width: 640px;"><p>Tell your travel story...</p>

我正在按照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);                 }
             });

在PHP方面,我正在通过以下方式获取数据(例如,为了方便起见,我只是将数据放入txt文件中(

$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
        fwrite($myfile, $_POST["luck"]);
        fclose($myfile);

但是我得到以下内容。 IMG标签缺少STYLE标签。

<p><br></p><img src="http://127.0.0.1/gallery/1/0336dcbab05b9d5ad24f4333c7658a0e.jpeg"  640px;"><p>Tell your travel story...</p>

我不确定如何正确检索数据? ajax请求是否存在问题,或者可能是我没有以正确的方式获取PHP中的数据?

任何建议都会有所帮助。

谢谢

看一下file_get_contents(php://input) 您可能需要在发送html字符串之前对其进行uri编码,才能在post数组中对其进行访问。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM