Jump to content

Ajax Calls in Self Made Component Based on Class "TUniHTMLFrame"


Kattes

Recommended Posts

Hi everyone,

I'm currently working on a UniGUI project where I need to make an AJAX call from JavaScript code within a TUniHTMLFrame component. I've been trying to set up the AJAX call using ajaxRequest, but I'm encountering difficulties in properly referencing the component to trigger the event handler on the server side.

Here is some code, which works fine in a standalone project - but I am not able to transfer this to my component code:

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  UniHTMLFrame1.HTML.Text :=
    '<!DOCTYPE html>' +
    '<html>' +
    '<head>' +
    '<title>Button Test</title>' +
    '<script type="text/javascript">' +
    'function buttonClicked() {' +
    '  ajaxRequest(MainForm.UniHTMLFrame1, "buttonClick", ["info=Ajax works fine!"]);' +
    '}' +
    '</script>' +
    '</head>' +
    '<body>' +
    '<button onclick="buttonClicked()">Click Me!</button>' +
    '</body>' +
    '</html>';
end;


procedure TMainForm.UniHTMLFrame1AjaxEvent(Sender: TComponent;
  EventName: string; Params: TUniStrings);
begin
  if EventName = 'buttonClick' then
  begin
    ShowMessage('Button was clicked with info: ' + Params.Values['info']);
  end;
end;

Despite my efforts, I haven't been able to get the AJAX call to work as expected. I've explored various approaches, including using window.parent, window.parent.Ext.getCmp, and direct references to the component's JSName, but none of them seem to be yielding the desired results.

Could someone please provide guidance on how to correctly set up the AJAX call within a TUniHTMLFrame component? Any insights or alternative approaches would be greatly appreciated.

Thanks in advance for your help!

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...