Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7542487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:10:46+00:00 2026-05-30T08:10:46+00:00

I have a URL generated by the server. Being in the client I don’t

  • 0

I have a URL generated by the server. Being in the client I don’t know if the URL will be : http://url/parameter or http://url/parameter?anotherPar=1 .

this value is available to a javascript variable:

  var theUrl = '{someURLgeneratedByTheServer}';

I’d like to use window.location.href passing some parameters, but I can’t just do it:

  window.location.href = theUrl + '?someClientGeneratedParameter=value&secondParameter=value2';

for this would be invalid if the server-generated URL already has some querystring parameters. I know that when I’m using jQuery’s Ajax method I can use the options parameter passing the data object with the needed querystring parameters, and jQuery itself is able to decide wheter it has to concat with ? or &, like this:

   $.ajax({
            type: "GET",
            url: theUrl,
            data: {someClientGeneratedParameter:'value', secondParameter:'value2'},
            success: callback 
        });

Is there a way to make a redirection using this concat mechanism of jquery before calling location.href? (something like below):

//supposition only, when  theUrl equals 'http://url/parameter?anotherPar=1'
var finalUrl = $.getMyFinalUrl({url: theUrl,
                 data: {someClientGeneratedParameter:'value', secondParameter:'value2'}
                });
window.location.href = finalUrl ;

Does it make sense or should I write my own method?

Thanks.

PS: using Asp.net MVC3 on the server + C#.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:10:48+00:00Added an answer on May 30, 2026 at 8:10 am

    How about something like this? Rip out the demo code and it’s very simple and let’s you pass parameters by array:

    function getURL(theUrl, extraParameters) {
        var extraParametersEncoded = $.param(extraParameters);
        var seperator = theUrl.indexOf('?') == -1 ? "?" : "&";
    
        return(theUrl + seperator + extraParametersEncoded);
    }
    
    
    // Test1
    var theUrl1 = "http://example.com/test"
    var extraParameters1 = {
        "someClientGeneratedParameter": "value",
        "secondParameter": "value2"
    };
    alert(getURL(theUrl1, extraParameters1));
    
    // Test2
    var theUrl2 = "http://example.com/?test=test"
    var extraParameters2 = {
        "someClientGeneratedParameter": "value",
        "secondParameter": "value2"
    };  
    alert(getURL(theUrl2, extraParameters2));
    

    Output:

    http://example.com/test?someClientGeneratedParameter=value&secondParameter=value2
    http://example.com/?test=test&someClientGeneratedParameter=value&secondParameter=value2

    Fiddle: http://jsfiddle.net/gjuqG/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a url string like this: http://www.google.com/cse?cx=017840637368510444960:ny1lmky7r-0&client=google-csbe&output=xml_no_dtd&q=simon+g I need to send this url
I'm trying to have my Struts2 app redirect to a generated URL. In this
I have an asp.net url path which is being generated in a web form,
I have URL scheme for my blog like this: http://www.example.com/%YEAR%/%MONTH%/%CATEGORY%/%POST_TITLE%/ Now i want to
I have this problem when I deploy, I really don't know how to solve
I am having trouble doing a reverse URL lookup for Django-generated feeds. I have
I have URL like: http://example.com#something , how do I remove #something , without causing
I have three values that are being generated dynamically in the code-behind of my
I have a dynamically generated list of URL's from our internal network. For each
Hi all I have a variable that is a YouTube url that is user-generated.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.