Jump to content

How to Get JS function result?


huayan889

Recommended Posts

15 minutes ago, huayan889 said:

It's OK to assign a value to the control, but now I want to return the result to the specified variable

Something like this,Delphi Code call js MD5 function,  Can it be realized?

UniQuery1.SQL.Text := 'select * from ss_customer_info where (customer_id=' + chr(39) +
    UniEdit1.Text + chr(39) + ') and  (admin_id =' + chr(39) + admin_id.Text + chr(39) +
    ') and  (admin_pass=' + chr(39) + MD5(fromCode(FpKey)) + chr(39) + ')';
  UniQuery1.Open;
 

Link to comment
Share on other sites

6 minutes ago, Sherzod said:

You can use it like this:


Uses ... IdHash, IdHashMessageDigest;

with TIdHashMessageDigest5.Create do
try
  MD5HashStr :=  HashStringAsHex(edPass.Text);
finally
  Free;
end;

 

MD5 is just an example, I need to use other encryption algorithms

Link to comment
Share on other sites

Just now, huayan889 said:

I mean, is there any way to call JS function in Delphi code to return the result.

Well, the algorithm is this:

JS fn call (client side, use ajaxRequest to send data to server) -> Handling OnAjaxEvent (server side) 

Link to comment
Share on other sites

  • 3 months later...

procedure TfFormFilterHistory.UniButton1Click(Sender: TObject);
var nStr: string;
begin
  nStr := 'var t1=%s.getEditorBody().outerText;'+ //1.call function 
          'ajaxRequest(%s.form, ''getHTMLtext'', [''t1=''+t1]);';  //2.send result to server
  nStr := Format(nStr, [Memo1.JSName, self.Name]);

  UniSession.SendResponse(nStr);
  UniSession.Synchronize; // MainModule.EnableSynchronousOperations=true,here is important
  ShowMessageN(FText); //show result
end;

procedure TfFormFilterHistory.UniFormAjaxEvent(Sender: TComponent;
  EventName: string; Params: TUniStrings);
begin
 if EventName='getHTMLtext' then
   begin
    FText:=Params.Values['t1'];  //3.receive result
   end;
end;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...