简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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