Jump to content

ajaxRequest Problem


freedowsRoO

Recommended Posts

Hello!

How can i have sure that ajaxEvent finish the execution? I need to use a function after the ajaxEvent  are processed. 

 

I'm triyng to use 'UniSession.SendFile()' in the event ajaxEvent but the application send more than one file to the client side, The first time that i click the button the application send 1 file per time, if i click the second time the application send 2 files and so on.... 

 

Is difficult to explain....

Link to comment
Share on other sites

On 5/19/2020 at 4:29 PM, Sherzod said:

Hello, 

OK, but do you have a simple testcase to check first?.. 

 

Sorry, i did not manage to reproduce them. The error occurs only in my application, i made a video to try to explain better.

 

Note in the video that the application stops at breakpoint only once, but on the client appears to save the file many times.

 

Link to comment
Share on other sites

On 5/23/2020 at 4:53 PM, andyhill said:

AjaxEvent ONE

Inside AjaxEvent ONE at end of event call AjaxEvent TWO

 

Thanks for reply but i have only one ajaxevent. The server trigger the unissession.sendfile many times.. 

Link to comment
Share on other sites

On 5/23/2020 at 2:16 PM, Sherzod said:

Sorry, is not very clear...

 

I managed to reproduce the problem. The problem is when i call the html2canvas function but i don´t know how to fix it.

 

To reproduce the problem, just click to 'send file' button more than one time.

SendFile.rar

Link to comment
Share on other sites

11 minutes ago, Sherzod said:

Well, right, how many clicks, as many request.

Just click, wait the download finish and click again and reapeat. 

 

In the first time that you click the application will send 1 file to save, the second time the application will send two, the third time three and etc...

Link to comment
Share on other sites

Also, your code seems to be "incomplete"

function click(sender, e, eOpts)
{
  ajaxRequest('#1', "getData", ["base64Data=teste"])
}
ajaxRequest('#1', "getData", ["base64Data="+canvas.toDataURL("image/jpeg,1.0")])
procedure TMainForm.UniButton1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName='getData' then
  Begin
    UniSession.SendFile(UniServerModule.FilesFolderPath+ 'unipdf.pdf');

  End;
end;

 

Link to comment
Share on other sites

18 hours ago, Sherzod said:

Also, your code seems to be "incomplete"


function click(sender, e, eOpts)
{
  ajaxRequest('#1', "getData", ["base64Data=teste"])
}

ajaxRequest('#1', "getData", ["base64Data="+canvas.toDataURL("image/jpeg,1.0")])

procedure TMainForm.UniButton1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName='getData' then
  Begin
    UniSession.SendFile(UniServerModule.FilesFolderPath+ 'unipdf.pdf');

  End;
end;

 

Yeh it is incomplete, i just made the example using the html2cavas with the ajaxrequest because the problem only show when i call de html2canvas function. In my main application i convert the base64 image and save on a PDF, after that i send the 'unisession.sendFile'.

Just focus on the problem, i click one time in the button and the server send me 2 files do download just it.

 

Thanks in advanced...

Link to comment
Share on other sites

4 hours ago, freedowsRoO said:

up

Hello,

Sorry for the late response.

One possible solution...:

1. Remove "JSInterface.JSCode..." from OnClick event

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
end;

2. You need to move the logic to ClientEvents.ExtEvents...

function click(sender, e, eOpts)
{
  sender.setDisabled(true);
  ajaxRequest(sender, "getData", ["base64Data=teste"]);
}

3. ClientEvents.UniEvents...

function ajaxCallback(sender, response)
{
    sender.setDisabled(false);
}

 

  • Like 1
Link to comment
Share on other sites

1 hour ago, Sherzod said:

Hello,

Sorry for the late response.

One possible solution...:

1. Remove "JSInterface.JSCode..." from OnClick event


procedure TMainForm.UniButton1Click(Sender: TObject);
begin
end;

2. You need to move the logic to ClientEvents.ExtEvents...


function click(sender, e, eOpts)
{
  sender.setDisabled(true);
  ajaxRequest(sender, "getData", ["base64Data=teste"]);
}

3. ClientEvents.UniEvents...


function ajaxCallback(sender, response)
{
    sender.setDisabled(false);
}

 

Nice, I'm already trying to do that but without success...

function click(sender, e, eOpts)
{
  html2canvas(document.getElementById(PanelCentral.jsID) , { dpi: 144 } ).then( 
    function(canvas) { '+
       var ctx = canvas.getContext("2d");      
       ctx.webkitImageSmoothingEnabled = false; 
       ctx.mozImageSmoothingEnabled = false;   
       ctx.imageSmoothingEnabled = false;      
       var myImage = canvas.toDataURL("image/jpeg,1.0"); 
       ajaxRequest('#1', "getData", ["base64Data="+myImage]); 
    } );
}

 

 

Link to comment
Share on other sites

11 minutes ago, Sherzod said:

ajaxRequest(sender, "getData", ["base64Data="+myImage]); 

 

A little question: Is this line correct?

html2canvas(document.getElementById(PanelCentral.jsID) , { dpi: 144 } )

If i need to use another component there i just call de name of the component?

Link to comment
Share on other sites

2 minutes ago, Sherzod said:

It seems not, what kind of object?

Any object, i need to set there the object that i want to take the screeshot. How it works ?  When the function was in the delphi click event i just use the code like: MyPanel.JsID or MyButton.JsID.

How it workd now that i change my function to ClientEvents?

Link to comment
Share on other sites

14 hours ago, freedowsRoO said:

function click(sender, e, eOpts) {   html2canvas(document.getElementById(PanelCentral.jsID) , { dpi: 144 } ).then(      function(canvas) { '+        var ctx = canvas.getContext("2d");              ctx.webkitImageSmoothingEnabled = false;         ctx.mozImageSmoothingEnabled = false;           ctx.imageSmoothingEnabled = false;              var myImage = canvas.toDataURL("image/jpeg,1.0");         ajaxRequest('#1', "getData", ["base64Data="+myImage]);      } ); }

function click(sender, e, eOpts) 
{
    html2canvas(document.getElementById(sender.id), {
        dpi: 144
    }).then(function(canvas) {
        var ctx = canvas.getContext("2d");
        ctx.webkitImageSmoothingEnabled = false;
        ctx.mozImageSmoothingEnabled = false;
        ctx.imageSmoothingEnabled = false;
        var myImage = canvas.toDataURL("image/jpeg,1.0");
        ajaxRequest(sender, "getData", ["base64Data= " + myImage]);
    });
}

 

Link to comment
Share on other sites

8 minutes ago, Sherzod said:

function click(sender, e, eOpts) 
{
    html2canvas(document.getElementById(sender.id), {
        dpi: 144
    }).then(function(canvas) {
        var ctx = canvas.getContext("2d");
        ctx.webkitImageSmoothingEnabled = false;
        ctx.mozImageSmoothingEnabled = false;
        ctx.imageSmoothingEnabled = false;
        var myImage = canvas.toDataURL("image/jpeg,1.0");
        ajaxRequest(sender, "getData", ["base64Data= " + myImage]);
    });
}

 

Ok, almost there... What if i need to change the 'sender.id' for another component? I need to take a screenshot of a panel not of my button(sender).

Link to comment
Share on other sites

3 minutes ago, freedowsRoO said:

What if i need to change the 'sender.id' for another component? I need to take a screenshot of a panel not of my button(sender).

In this case. And with our solution, you can use it like this.

1. For example, you can use a combobox for select the another component id.

  ...
  YourMainButton.JSInterface.JSAssign('screenshotObjId', [YourCustomComponent.JsID]);
  ...

2. 

function click(sender, e, eOpts) 
{
    html2canvas(document.getElementById(sender.screenshotObjId), {
        dpi: 144
    }).then(function(canvas) {
        var ctx = canvas.getContext("2d");
        ctx.webkitImageSmoothingEnabled = false;
        ctx.mozImageSmoothingEnabled = false;
        ctx.imageSmoothingEnabled = false;
        var myImage = canvas.toDataURL("image/jpeg,1.0");
        ajaxRequest(sender, "getData", ["base64Data= " + myImage]);
    });
}

 

  • Like 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...