0

I trying to send HTML code to php file so i can save into database.

I am getting HTML code from tinyMCE.

I tried all method JSON, encodeURIComponent, encodeURI and escape().

It works perfectly on localhost (on my PC using Wampserver) but not on server (hosted on namecheap).

When i am send simple value like "Hello world" it works perfectly but not full HTML code.

Please check the below code i am using -

$('#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>

in PHP

<?php
print_r($_POST);
?>

ERROR:

POST https://www.mywebiste.com/phpfile 404

ISSUE RESOLVE after killing myself 3 days -

https://stackoverflow.com/questions/44623323/handling-json-data-in-codeigniter-controller
10
  • 404 means file doesn't exist. Did you write which file you are calling in AJAX? This is wrong url: "url to php file" Commented Apr 25, 2019 at 10:28
  • When i sent simple value like "Hello world" It gets response without any error. Commented Apr 25, 2019 at 10:29
  • 1
    var templatedata = $('#htmldata').val(); I don't see any element with id htmldata in your html file. Commented Apr 25, 2019 at 10:30
  • Its getting from tinyMCE <textarea id ="#htmldata"></textarea> Where the HTML code its getting from. Commented Apr 25, 2019 at 10:31
  • does console.log(templatedata); contail any values? Also maybe the path in your url is wrong so you get a 404 error Commented Apr 25, 2019 at 10:33

1 Answer 1

0

ISSUE RESOLVE after killing myself 3 days -

https://stackoverflow.com/questions/44623323/handling-json-data-in-codeigniter-controller
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.