[英]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()
}
})
});
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.