0

jQuery を使用して、PHP ファイルによって生成されるインライン CSS を追加したいと考えています。<style>タグの間にPHPファイルの内容を印刷できるようにしたいです。

JS ファイルの関連部分は次のとおりです。

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

style.php ファイルは元の CSS を問題なく生成するので、変更したくありませんが、上記を実行すると、PHP ファイルに関連して 500 Internal Server Error が発生します。

誰でも助けてもらえますか?

4

1 に答える 1

3

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);
});
于 2013-05-28T14:46:27.330 に答える