dermoritz dermoritz - 2 years ago 106
Javascript Question

How to redirect to same page with parameters given as json

On my site i am using jQuery's ajax this way:

type: 'GET',
url: productSearch.searchUrl,
data: parameter,
dataType: 'json'

"data" contains all parameters.

On some state i want to redirect the user to the same page but with all paramters from "data" appended.


data = {
"par1" = "value1",
"par2" = "value 2"

current url:

should be redirected to

How to do this (with jQuery?)?

Answer Source


var data = {
    "par1": "value1",
    "par2": "value 2"
var params = $.param(data);
if (location.href.match(/\?/)) {
    location.href += params;
} else {
    location.href += '?' + params;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download