php - 使用 Ajax 将 HTML 和样式代码传递给 PHP - 出现 404 服务器错误
问题描述
我试图将 HTML 代码发送到 php 文件,以便我可以保存到数据库中。
我从 tinyMCE 获取 HTML 代码。
我尝试了所有方法 JSON、encodeURIComponent、encodeURI 和 escape()。
它在 localhost(在我使用 Wampserver 的 PC 上)上完美运行,但在服务器上(托管在 namecheap 上)上运行良好。
当我发送像“Hello world”这样的简单值时,它可以完美运行,但不是完整的 HTML 代码。
请检查我正在使用的以下代码 -
$('#updatehtml').on('click', function(e){
e.preventDefault();
tinyMCE.triggerSave();
var templatedata = $('#htmldata').val();
$.ajax({
type:"POST",
url: "url to php file",
data: {template : templatedata},
dataType: "html",
success: function (data){
alert(data);
console.log(data);
}
});
});
HTML
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Sevillana" />
<style>
body{background: #ffffff; font-family: Lucida Sans; width: 80%; margin: 0 auto; border: 1px solid gray; border-radius: 10px; color: #353333;font-size: 14px;}
p{background: #b3fc7b; border-bottom: 3px #b3fc7b solid; background-repeat: no-repeat; padding: 3em; color: #FFF; clear: left; text-align: center; border-radius: 10px 10px 0px 0px;}
h1{text-shadow: 1px 7px 5px #000;font-family: Sevillana;font-size: 4em;margin:0px;}
h2{width: 89%;margin: 0 auto;padding: 0px 0px 5px 0px;font-family: Sevillana;font-size: 2em;color: #FFF; border-radius:10px 0px 10px 0px; background: #b3fc7b;text-shadow: 1px 2px 5px #000;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
在 PHP 中
<?php
print_r($_POST);
?>
错误:
POST https://www.mywebiste.com/phpfile 404
杀死自己 3 天后的问题解决 -
https://stackoverflow.com/questions/44623323/handling-json-data-in-codeigniter-controller
解决方案
杀死自己 3 天后的问题解决 -
https://stackoverflow.com/questions/44623323/handling-json-data-in-codeigniter-controller
推荐阅读
- javascript - 我应该如何根据javascript中的参数类返回一个类?
- tensorflow - 如何对tensorflow中的张量执行np.append()类型的操作?
- php - 如何计算每个给定评分的平均评分?
- javascript - 触发按钮单击事件时,滚动条移动到顶部。我想在特定位置停止滚动条移动
- algorithm - 我如何有效地找到这个约束系统中变量的最小值和最大值?
- python - _pickle.UnpicklingError: unpickling 堆栈下溢
- ios - JSON 访问数组内的多个实例
- amazon-web-services - 将 json 传递给 lambda 函数
- python - 如何将单词映射到数字以输入到 Tensorflow 神经网络
- php - 替换部分url htaccess后重定向所有url