Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
14
rated 0 times [  21] [ 7]  / answers: 1 / hits: 20708  / 15 Years ago, sun, july 19, 2009, 12:00:00

This is one of those situations where I feel like I'm missing a crucial keyword to find the answer on Google...



I have a bag of parameters and I want to make the browser navigate to a GET URL with the parameters. Being a jQuery user, I know that if I wanted to make an ajax request, I would simply do:



$.getJSON(url, params, fn_handle_result);


But sometimes I don't want to use ajax. I just want to submit the parameters and get a page back.



Now, I know I can loop the parameters and manually construct a GET URL. For POST, I can dynamically create a form, populate it with fields and submit. But I'm sure somebody has written a plugin that does this already. Or maybe I missed something and you can do it with core jQuery.



So, does anybody know of such a plugin?



EDIT: Basically, what I want is to write:



$.goTo(url, params);


And optionally



$.goTo(url, params, POST);

More From » jquery

 Answers
49

jQuery Plugin seemed to work great until I tried it on IE8. I had to make this slight modification to get it to work on IE:



(function($) {
$.extend({
getGo: function(url, params) {
document.location = url + '?' + $.param(params);
},
postGo: function(url, params) {
var $form = $(<form>)
.attr(method, post)
.attr(action, url);
$.each(params, function(name, value) {
$(<input type='hidden'>)
.attr(name, name)
.attr(value, value)
.appendTo($form);
});
$form.appendTo(body);
$form.submit();
}
});
})(jQuery);

[#99099] Tuesday, July 14, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daytonm

Total Points: 519
Total Questions: 83
Total Answers: 89

Location: Saudi Arabia
Member since Mon, Sep 5, 2022
2 Years ago
;