Recent

Author Topic: append new params to the searchParams[SOLVED]  (Read 2767 times)

krolikbest

  • Full Member
  • ***
  • Posts: 246
append new params to the searchParams[SOLVED]
« on: April 24, 2021, 07:07:34 pm »
Hi,

it'd be nice to send from my pas2js file something outside. Let's say after pushing WButton it sends to fphttpserver some parameters which then I'm able to catch with aReqest.QueryFields.Values[..] and work with. A little blindly I try something like
Code: Pascal  [Select][+][-]
  1. WButton.OnClick()
  2. var
  3.   paramsOut3 : TJSURLSearchParams;
  4.   url : TJSURL;
  5.   P : TJSObject;
  6.  
  7. begin
  8.   {http://192.168.1.4:8080/?txt=22}                   //this is my href
  9.  
  10.   p:=New(['url',window.locationString]);
  11.   url:=TJSURL(p);                                             // now it should be already url.href assigned
  12.   url.href:=string(p['url']);                                 //but doesn't and I have to make it by hand,
  13.   showmessage(url.href);                                  //seems to be ok...
  14.   paramsOut3:=url.SearchParams;                    //so now time to separate searchParams
  15.   paramsOut3.append('txt2','12s');                    //error: cannot append to 'undefined', why is undefined?
  16. end;

So probably I try make it wrong. Someone knows how to modify url by appendin new params from pas2js?

Regards,

----
Also this doesn't seem to be ok
Code: Pascal  [Select][+][-]
  1.   url:=TJSURL(window.location);
  2.   paramsOut3:=url.SearchParams;
  3.   paramsOut3.set_('txt','34');    //error undefined
  4.  
« Last Edit: April 24, 2021, 09:16:02 pm by krolikbest »

krolikbest

  • Full Member
  • ***
  • Posts: 246
Re: append new params to the searchParams
« Reply #1 on: April 24, 2021, 09:15:28 pm »
That works.
Code: Pascal  [Select][+][-]
  1.    url:=TJSURL.new(window.locationString);
  2.   paramsOut3:=TJSURLSearchParams.new;
  3.   paramsOut3:=url.SearchParams;
  4.   paramsOut3.set_('txt','12s');
  5.   console.log(url.href);
  6.   window.location.href:=url.href;
  7.  
where
  paramsOut3 : TJSURLSearchParams;
  url : TJSURL;

 

TinyPortal © 2005-2018