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 127213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:26:27+00:00 2026-05-11T05:26:27+00:00

In a web application that makes use of AJAX calls, I need to submit

  • 0

In a web application that makes use of AJAX calls, I need to submit a request but add a parameter to the end of the URL, for example:

Original URL:

http://server/myapp.php?id=10

Resulting URL:

http://server/myapp.php?id=10&enabled=true

Looking for a JavaScript function which parses the URL looking at each parameter, then adds the new parameter or updates the value if one already exists.

  • 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. 2026-05-11T05:26:28+00:00Added an answer on May 11, 2026 at 5:26 am

    A basic implementation which you’ll need to adapt would look something like this:

    function insertParam(key, value) {     key = encodeURIComponent(key);     value = encodeURIComponent(value);      // kvp looks like ['key1=value1', 'key2=value2', ...]     var kvp = document.location.search.substr(1).split('&');     let i=0;      for(; i<kvp.length; i++){         if (kvp[i].startsWith(key + '=')) {             let pair = kvp[i].split('=');             pair[1] = value;             kvp[i] = pair.join('=');             break;         }     }      if(i >= kvp.length){         kvp[kvp.length] = [key,value].join('=');     }      // can return this or...     let params = kvp.join('&');      // reload page with new params     document.location.search = params; } 

    This is approximately twice as fast as a regex or search based solution, but that depends completely on the length of the querystring and the index of any match


    the slow regex method I benchmarked against for completions sake (approx +150% slower)

    function insertParam2(key,value) {     key = encodeURIComponent(key); value = encodeURIComponent(value);      var s = document.location.search;     var kvp = key+'='+value;      var r = new RegExp('(&|\\?)'+key+'=[^\&]*');      s = s.replace(r,'$1'+kvp);      if(!RegExp.$1) {s += (s.length>0 ? '&' : '?') + kvp;};      //again, do what you will here     document.location.search = s; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a web application that will use a lot of ajax calls. The
I have am working on a web application that makes use of helper classes.
I need to design a page for a web application that makes sense for
I have an ASP .NET Web Forms application that makes use of the 'WebMethod'
I'm developing a web application, where I use jQuery to make Ajax calls to
I have a certain web application that makes upwards of ~100 updates to an
I need to make a section in my web application that has multiple forms,
I have a PHP application that calls web services APIs to get some objects
In our web application,we have do some ajax request,so we may meet the cross
I'm working on a client-side webapplication that makes heavy use of JavaScript and Ajax

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.