使用 Ajax 将 HTML 和样式代码传递给 PHP - 获取 404 服务器错误



我试图将HTML代码发送到php文件,以便我可以保存到数据库中。

我正在从tinyMCE获得HTML代码。

我尝试了所有方法JSON,encodeURIComponent,encodeURI和escape((。

它在本地主机上(在我的电脑上使用Wampserver(上完美运行,但在服务器上(托管在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

最新更新