如何将相同类型的多个参数传递给jQuery Get [英] How do you pass multiple parameters of the same type to jQuery Get
问题描述
我正在尝试使用jQuery $ .get从网站获取一些数据。我需要设置2个相同类型的参数:
I'm trying to GET some data from a site using jQuery $.get. I need to set 2 parameters of the same type:
..&q=Some Text&q=Some other text
jQuery似乎用第二个实例覆盖了q的第一个实例,只发送了1个。 ?
jQuery appears to be overwriting the first instance of q with the second and only sending 1. Any way around this?
这是我尝试使用的代码:
This is the code I was trying to use:
var params = {
"otherParam":"x",
"q":text,
"q":title
};
$.get(url, params, mySuccessFunction);
推荐答案
尝试:
var params = {
"otherParam": "x",
"q": [ text, title ]
};
edit —更多信息:像这样的数组值参数由jQuery专门处理。为了安抚许多常见的服务器框架,默认情况下(因为我认为是1.5或1.6版本),这些将导致参数名称包含[](开括号和近括号字符)作为后缀(没有数字,与我的错误相反)评论如下)。如果你不想这样,你可以设置
edit — more information: array-valued parameters like that are treated specially by jQuery. To appease many common server frameworks, by default (since release 1.5 or 1.6 I think) those will result in parameter names that include "[]" (open- and close-bracket characters) as a suffix (no number, contrary to my erroneous comment below). If you don't want that, you can set
jQuery.ajaxSettings.traditional = true;
它只是q而不是q []。
and it'll just be "q" instead of "q[]".
这篇关于如何将相同类型的多个参数传递给jQuery Get的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!