Message from JavaScript discussions
June 2017
— Well, lets me explain from 0, to avoid misunderstand between us Muhammad
So i created menu with a json, and the json's structure is
id : xx, name : xxx
and then when i clicked the menu, it will open a new page and its was
function bukapaket(id) {
window.open("paket.html?id="+id+" ","_self");
}
so it will resulted as
/paket.html?id=xxx
now i have call another json
and the structure is
id=xxx,menu_id=xxx,nama=xxx,etc
where is menu_id = the id the menu's id.
— So you want to know how to get the query parameter from your page (the „id=xxx“ part) in Client JavaScript for using it in something like an Ajax request?
— If so, u need to get the URL (i think with window.location) and then use it like this:
— Var url = new URL(window.location);
var id = url.searchParams.get("id");
— But that’s a new JS Feature so i don’t Know how compatible it is
— Maybe if not compatible, you can search polyfill for search params
— Well, its k dunklesToast Muhammad its solved
— 😁
— Btw is it possible to convert json to array, and sort it via looping with jscript/jquery ?
— Sure, you can use JSON.parse to convert JSON string to JSON object
— Well, to avoid misunderstanding, i have json like this :id: id, name: name, date: date
can i convert it to array and make it like this :date:date, id:id, name:name
?