简体   繁体   中英

How to make url in jQuery using query parameter?

I am trying to use this plugin: https://github.com/tombonner/jurlp .

I want to make url using parameter. Can we make using this plugin?

Here is my code

// first case
var a = 'http://abc/deappsl/index.html?word=abc';
var abc = {
  test:"lo"
}

// second case
var a = 'http://abc/deappsl/index.html';
var abc = {
  test:"lo",
  p:'er'
}

// expected output
//first
//http://abc/deappsl/index.html?word=abc&test=lo

//second
//http://abc/deappsl/index.html?test=lo&p=er

http://plnkr.co/edit/IEnUPyGAgCCCPeII0xh3?p=preview

I have two cases

  • First In url I have already "?" and add param it give expected result using "&"
  • second if url does not contain "?" then it add param with "?" and "&"

Can we use this plugin to make url?

Any update ?

You can parse the original URL using $.jurlp

var url = $.jurlp(a);

Then you can update the query parameters with the .query() method.

url.query(abc);

Then see the new URL

console.log(url.href);

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM