I have a weird situation and I can't seem to find the answer on Google.
I am taking a javascript array, applying JSON.stringify to it, and then posting via AJAX to a php controller for storing the now json_encoded array in a table. Upon posting via ajax, the $_POST is somehow stripping the styles attribute on the html being submitted.
Here is the sample html being grabbed via javascript/jquery:
<"div class="blahblah" style="border:1px solid #000000;"><strong>test</strong></div>
Here is the AJAX post code:
var post_data = [];
$("divclasshere").each(function(){
post_data.push({html:$(this).html()});
});
var data = JSON.stringify(post_data);
$.ajax({
type: "POST",
url: "save",
data: { content: data },
success: function(result){
}
});
And here is the controller function that saves it to the db:
$data = array(
'content' => $this->input->post('content')
);
$this->db->update('table', $data);
If I print_r on the data on the PHP controller, I get (example)
<div class="blahblah"><strong>test</strong></div>
But no styles attribute on the div class="blahblah" element. I am using CodeIgniter if that makes a difference? In some cases, it strips the first part: style="border:1px and leaves solid #000000;"
EDIT:
Here is what gets posted (as an example):
content:[{"html":"<div class=\"content\" style=\"border:1px solid #000000;\"></div>"}]
And here is what gets print_r'd:
<pre>[{"html":"<div class=\"content\" solid #000000;\"></div>"}]