How to pass string with & via get in javascript [duplicate] - javascript

This question already has answers here:
Escaping ampersand in URL
(8 answers)
Closed 5 years ago.
I have a problem, I wonder if someone could help me, I need to pass a string that contains (&) via get. Example:
.com/index.php?nome=name=AA&BB&age=18&city=....
This way the name arrives from the other sides only AA

You have to encode the parameter before sending it to the server:
var url = "normal url?" + encodeURIComponent("get params");

Related

Getting Product ID from URL using JavaScript [duplicate]

This question already has answers here:
Last segment of URL with JavaScript
(30 answers)
How do I parse a URL into hostname and path in javascript?
(26 answers)
Closed 1 year ago.
i need to get the product id from an url into a var
https://instrumentall.md/ro/6167922/
can someone help me please?
In JavaScript use window.location.href to get the value of the url. Than process it as a normal string.

How to replace a string in javascript only when it's comes before another string using regex? [duplicate]

This question already has answers here:
REGEX: Capture Filename from URL without file extension
(5 answers)
JavaScript Regexp to replace a value only when it follows certain characters?
(2 answers)
Closed 3 years ago.
I want to replace xx with . in this string 100x100/<name>xx-somename-xxjpg but only xx comes next to jpg.
'100x100/<name>xx-somename-xxjpg'.replace(/(xx(jpg|jpeg|png))/,'$')
What I get -> 100x100/<name>xx-somename-$
What I expect-> 100x100/<name>xx-somename-.jpg
How do I do it?
'100x100/<name>xx-somename-xxjpg'.replace(/(xx)(?=jpg|jpeg|png)/,'.')

How do I convert this response to HTML? [duplicate]

This question already has answers here:
Unicode value \uXXXX to Character in Javascript
(3 answers)
Closed 3 years ago.
I make an XMLHttpRequest and receive a response that looks like this
\u003Cdiv class=\u0027upcoming-events\u0027\u003E\r\n \u003Ch3 class=\u0027h3-med\u0027\u003E\u003Ca href=\u0022/user-calendar\u0022\u003ECalendar\u003C/a\u003EUpcoming\u003C/h3\u003E\r\n
What is this response type and how would I convert it to HTML in Javascript?
You shouldn't have to perform any conversion; these Unicode characters should be interpreted correctly as-is.
var string = "\u003Cdiv class=\u0027upcoming-events\u0027\u003E\r\n \u003Ch3 class=\u0027h3-med\u0027\u003E\u003Ca href=\u0022/user-calendar\u0022\u003ECalendar\u003C/a\u003EUpcoming\u003C/h3\u003E\r\n";
document.body.innerHTML = string;
<body>
</body>

extracting text between two characters [duplicate]

This question already has answers here:
Regular expression to get a string between two strings in Javascript
(13 answers)
Closed 6 years ago.
Having a string like:
"*this* not that"
I can select *this*
\*(.*?)\*
but I'm not able to get only this.
what I am trying to achieve is to replace -this- by a new string. What's the easiest way to do that ?
you can try:
"*this* not that".replace(/\*.*\*/,'*new_string*');
//"*new_string* not that"

How to set a variable based on the first string in the URL after a symbol? [duplicate]

This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 8 years ago.
At the moment I am doing this:
var token = document.location.href.split('?_sft_category=')[1];
Which is ok if my URL is:
http://www.example.com/xchanges/results/?_sft_category=sky
I get sky in that case as a var, but if my URL becomes
http://www.example.com/xchanges/results/?_sft_category=sky#comboFilters%5BAgency%5D=.TBWA
In that case I obviously get everything after = while instead I would like to get ONLY the first string after '?_sft_category='
url = "http://www.example.com/xchanges/results/?_sft_category=sky";
alert(url.split('?_sft_category=')[1].match(/[A-z]+/));
url ="http://www.example.com/xchanges/results/?_sft_category=sky#comboFilters%5BAgency%5D=.TBWA";
alert(url.split('?_sft_category=')[1].match(/[A-z]+/));
Demo

Categories

Resources