繁体   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