Ok I using something like this
$.getJSON("http://myurl.com/search-ext.json&type=aaaaaa&callback=?",
working fine but now I need to add another type variable like this:
$.getJSON("http://myurl.com/search-ext.json&type=aaaaaa&type=bbbbb&callback=?",
Yes, they ha开发者_如何学Pythonve the same name.... so can I insert another type or is there a way to swap out the string with an onclick?
Add []
to the key in your URL:
$.getJSON("http://myurl.com/search-ext.json&type[]=aaaaaa&type[]=bbbbbb&callback=?",
Also, I don't know if you did this on purpose or not, but it at least appears as if you need a ? after .json:
$.getJSON("http://myurl.com/search-ext.json?type[]=aaaaaa&type[]=bbbbbb&callback=?",
Then, for instance in PHP, you will have an array on the server:
$_GET['type'] ~ array('aaaaaa','bbbbbb')
EDIT
Following the additional comments, I believe this is what you're looking for:
http://plugins.jquery.com/project/query-object
var newerQuery = $.query.SET('type', 'bbbbb');
var newURL = "http://myurl.com/search-ext.json?" + newerQuery;
$.getJSON(newURL);
An example:
http://jfcoder.com/test/gettypes.php?type=aaaaaa&callback=MyCallback
EDIT 2
<a href="href://www.somewhere.com/?type=aaaaaa&other=yes&another=yes&yeti=neverseen"
onClick="return replaceType(this,'bbbbbb')">Link</a>
function replaceType(el, value) {
sub = el.href.substring(0,el.href.indexOf('?'));
split = el.href.substring(el.href.indexOf('?')+1).split("&");
for (var i = 0; i < split.length; i++) {
if (split[i].indexOf('type=') !== 0) continue;
split[i] = encodeURI("type="+value);
}
el.href = sub + "?" + split.join('&');
alert(el.href);
return false;
}
http://jsfiddle.net/Phjsv/1/
精彩评论