dqwh1208 2015-01-31 16:21
浏览 47

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

I am using Summernote text editor. I am collecting HTML in following way:

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({
                 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(

$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.

<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?

Any suggestions would be helpfull....

Thanks

  • 写回答

1条回答 默认 最新

  • dongtiran7769 2015-01-31 19:15
    关注

    Take a look at 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.

    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程