简体   繁体   English

如何通过jQuery / ajax将下拉样式值传递给我的php文件?

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

Here's the markup for my dropdown: 这是我的下拉菜单的标记:

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

And the jQuery I'm using right now: 我现在正在使用的jQuery:

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

This gives me a console error of "Uncaught SyntaxError: Unexpected token +". 这给了我一个控制台错误“ Uncaught SyntaxError:意外的标记+”。 All I'm trying to do is pass $_GET['theme'] on to my style.php so I can process it with conditionals. 我要做的就是将$ _GET ['theme']传递给我的style.php,这样我就可以使用条件处理它。 Any advice? 有什么建议吗?

Create data as an object, you have syntax issues in your code 将数据创建为对象,代码中存在语法问题

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

You have problem with your code. 您的代码有问题。 You need to provide key value pair while creating an object in JavaScript reference 在JavaScript 参考中创建对象时,需要提供键值对

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

Jsfiddle 的jsfiddle

do it like this............. 像这样做.............

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

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


    $.ajax({

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



                    }//end of success
            });

        });

i always used this technique then fetch it using 我一直使用这种技术,然后使用

   $theme = $_GET['theme'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何使用jquery ajax在webapi控制器中将webform值作为模型类传递 - how can i pass my webform value in webapi controller as a model class using jquery ajax 如何在jQuery中通过Ajax将文件保存以发送到服务器? - How can I send a file, for saving, to my server, via ajax, in jQuery? 如何立即更新 jquery 中的选择器下拉值? - How can I instantly update my selector dropdown value in jquery? 通过ajax,php,jquery传递复选框的值 - Pass the value of checkbox via ajax, php, jquery 我可以从浏览器控制台(通过AJAX)将信息发送到本地/远程主机上的php文件吗? - Can I send information from browser console (via AJAX) to my php file on local/remote host? 如何通过JQuery Ajax调用在PHP中验证表单? - How do I validate my form within PHP via JQuery Ajax call? 我如何将下拉值传递给 ajax 控制器? - How i pass the dropdown value to ajax controller? jQuery UI自动完成:如何通过Ajax调用传递其他数据? - jQuery UI Autocomplete: How can I pass additional data with my Ajax call? 将下拉列表的值传递到其他页面中的文本框-PHP / jQuery / AJAX - Pass value of a dropdown to a textbox in a different page - PHP/jQuery/AJAX 如何使用jQuery load()方法将从txt文件加载的链接设置为HTML样式? - How can I style links I loaded from a txt file with the jQuery load() method into my HTML?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM