Reputation: 532
I want to use jQuery to add some inline CSS which is generated by a PHP file. I want to be able to print the contents of the PHP file between the <style>
tags.
Here's the relevant piece of the JS file:
$('#settings button.theme').on('click', function(){
var whichone = $(this).data('file');
$('<style type="text/css" media="screen" id="changer"></style>')
.appendTo('head');
$('#changer').load('http://example.com/css/style.php?details=' + whichone);
});
I don't want to change the style.php file as it generates the original CSS quite happily, but when I do the above, I'm getting a 500 Internal Server Error in relation to the PHP file.
Can anyone help please?
Upvotes: 0
Views: 74
Reputation: 78585
Instead of trying to load the CSS via AJAX, just dynamically set the href attribute:
$('#settings button.theme').on('click', function(){
var whichone = $(this).data('file');
$('<link rel="stylesheet" type="text/css" media="screen" id="changer" />')
.appendTo('head').attr('href', 'http://example.com/css/style.php?details=' + whichone);
});
Upvotes: 3