簡體   English   中英

如何通過jQuery / ajax將下拉樣式值傳遞給我的php文件?

[英]How can I pass my dropdown style value on to my php file via jQuery/ajax?

這是我的下拉菜單的標記:

    <select id="themes">
        <option selected="selected">Themes:</option>
        <option value="default">Default</option>
        <option value="red">Red</option>
        <option value="bw">Black and White</option>
        <option value="invert">Invert</option>
    </select>

我現在正在使用的jQuery:

$("#themes").change(function() {
    $.ajax({
    url: "css/style.php",
    method: "GET",
    data: {"theme="+$(this).val(); }
    })
});

這給了我一個控制台錯誤“ Uncaught SyntaxError:意外的標記+”。 我要做的就是將$ _GET ['theme']傳遞給我的style.php,這樣我就可以使用條件處理它。 有什么建議嗎?

將數據創建為對象,代碼中存在語法問題

$("#themes").change(function () {
    $.ajax({
        url: "css/style.php",
        method: "GET",
        data: {
            theme: $(this).val()
        }
    })
});

您的代碼有問題。 在JavaScript 參考中創建對象時,需要提供鍵值對

$("#themes").change(function() {
    $.ajax({
       url: "css/style.php",
       method: "GET",
       data: {
         theme: $(this).val()
       }
    });
});

的jsfiddle

像這樣做.............

    $("#themes").change(function(){

    var theme = $(this).val();


    $.ajax({

                 url: "css/style.php",
                  method: "GET",
                data: {theme : theme },                                                                                                     
                success:  function(data) {



                    }//end of success
            });

        });

我一直使用這種技術,然后使用

   $theme = $_GET['theme'];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM