This topic is locked

ajax.addPDF API

7/15/2020 3:26:05 AM
PHPRunner General questions
rdf author

Hi PHPR Community,
I'm not sure what's happening but using just the code found on the ajax.addPDF online manual doesn't seem to work. No error and I used JavaScript alert() to get any return value from a variable nothing seem to show unless if I remove the ajax.addPDF() block then I get the return value.
Thank you.

Sergey Kornilov admin 7/15/2020

The code from the manual does work. It is hard to understand what you doing though as you cannot "return value from a variable", this is a function, not a variable. Also it is not supposed to return any values:

https://xlinesoft.com/phprunner/docs/ajax_addpdf.htm

rdf author 7/15/2020



The code from the manual does work. It is hard to understand what you doing though as you cannot "return value from a variable", this is a function, not a variable. Also it is not supposed to return any values:

https://xlinesoft.com/phprunner/docs/ajax_addpdf.htm


Hi Sergey,
Ok this is what I did.

  • I created a custom button on the View page named: formhf_edit_button
  • CLIENT BEFORE code:



//just for debugging purpose...

alert('trigger client before');

params["from_client_before"] = "from client before";
//declare ajax.addPDF

ajax.addPDF("pdf", {});

return false;


  • SERVER code:



//for debugging purpose...

$result["from_server"] = $params["from_client_before"] . "->" . "from server ->" . "to client after";
//initiate PHP function

file_put_contents("file.pdf", $params["pdf"]);


  • CLIENT AFTER code:



//for debugging purpose...

alert('trigger client after');

alert(result["from_server"]);



  • The alert() on CLIENT BEFORE will show. But not the alert() on CLIENT AFTER.
  • But if I comment the code on the CLIENT BEFORE:



//ajax.addPDF("pdf", {});

//return false;



Then, it will trigger the CLIENT AFTER alert().
On what I understand, its like the ajax.addPDF() on the CLIENT BEFORE doesn't get initiated.
If I comment it, the tri-part event will run normally and even save a file.pdf (which is invalid because ajax.addPDF() is commented).

M
MikeT 7/16/2020

I think you need to use/define a callback in the ClientBefore event to trigger an after event, it's mentioned in the documentation you referenced.