dermoritz dermoritz - 5 months ago 34
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?)?



var data = {
    "par1": "value1",
    "par2": "value 2"
var params = $.param(data);
if (location.href.match(/\?/)) {
    location.href += params;
} else {
    location.href += '?' + params;