I've trying to solve this for the last five days now, but nothing works. I've viewed every single post on the subject and nothing helps. I am using an OpenCart CMS and would like to send a simple jquery variable from one file to another with ajax and post so it can change the background color of the css file. To make this clear why the file is not with .php extension read this tutorial http://net.tutsplus.com/tutorials/php/supercharge-your-css-with-php-under-the-hood/ especially the Elegant Method. So this is the code of the ajax
$(document).ready(
function()
{
var headerDefaultColor = "#126FA8";
$.ajax({
url: "view/stylesheet/supercharge.css",
data: {cell: headerDefaultColor},
type: "POST",
async: false,
success: function(data) {
console.log("Send");
},
error: function(data){
console.log("Error");
}
})
.done(function(cell) { console.log("Done success: " + cell); })
.fail(function() { console.log("error"); })
.always(function() { console.log("complete"); })
});
This is the code for the css
<?php header("Content-type: text/css"); ?>
<?php
$headerColor = null;
var_dump($_POST['cell']);
if(isset($_POST['cell'])){
$headerColor = $_POST['cell'];
} else {
$headerColor = "Nothing happends, again!!";
}
?>
#header {
background-color: <?php echo $headerColor; ?>;
}
This is what i get in the console:
Send index.php:103
Done success:
<pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'#126FA8'</font> <i>(length=7)</i>
</pre>
#header {
background-color: #126FA8;
}
However this is what i get in the css file. It should send the hex code, however it doesn't and it generated a Notice: Undefined index: cell and here is the output:
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: cell in C:\Program Files (x86)\wamp\www\opencart-1.5.5.1\upload\admin\view\stylesheet\supercharge.css on line <i>14</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0004</td><td bgcolor='#eeeeec' align='right'>250160</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\Program Files (x86)\wamp\www\opencart-1.5.5.1\upload\admin\view\stylesheet\supercharge.css' bgcolor='#eeeeec'>..\supercharge.css<b>:</b>0</td></tr>
</table></font>
<pre class='xdebug-var-dump' dir='ltr'><font color='#3465a4'>null</font>
</pre>
#header {
background-color: Nothing happends, again!!;
}
I tried with isset() and it doesn't work i tried with empty() it doesn't work, and also viewed every singe search result that google gave me nothing works. So i want the var headerDefaultColor to be send to the .css file and change the background color with php and not with jquery (which works fine). What am i missing here?