[英]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.