728x90
Adding a parameter to the URL with JavaScript - Stack Overflow
Adding a parameter to the URL with JavaScript
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...
stackoverflow.com
You can use one of these:
- https://developer.mozilla.org/en-US/docs/Web/API/URL
- https://developer.mozilla.org/en/docs/Web/API/URLSearchParams
Example:
var url = new URL("http://foo.bar/?x=1&y=2");
// If your expected result is "http://foo.bar/?x=1&y=2&x=42"
url.searchParams.append('x', 42);
// If your expected result is "http://foo.bar/?x=42&y=2"
url.searchParams.set('x', 42);
결론:
url.searchParams.set('x', 42);
내 코드:
url.searchParams.set("page", page); //&page=1
728x90
'Javascript > Javascript' 카테고리의 다른 글
[자바스크립트] module 사용법 3가지 (0) | 2022.05.09 |
---|---|
[자바스크립트] 조코딩-카카오API 활용실습 (0) | 2022.05.07 |
자바스크립트 라이브러리 목록 (0) | 2022.05.03 |
[자바스크립트] for문과 foreach 실전 예제 비교 (0) | 2022.04.30 |
[자바스크립트] Array.from( {length} 구문에서 {length}은 유사배열? (0) | 2022.04.27 |