-1

Possible Duplicate:
How to call a PHP function in JavaScript?

i have a form to print to a POS printer. Problem 1 is that i cant print directly, Mybe in google chrome in kioskmode.. so. i would like to call a function after the windows be closed from printing. code is like this:

    <script type="text/javascript">
        $(function(){
            $('#printOut').click(function(e){
                e.preventDefault();
                var w = window.open();
                var printOne = $('.contentToPrint').html();
                var printTwo = $('.termsToPrint').html();
                w.document.write('<html>' + printOne + '<hr />' + printTwo   ) + '</body></html>';

                w.window.print();

                w.document.close();
   I INSERTED HERE>>>   insert();  <<<<<<<<<<< AND  WORKS BUT NOT BY CLOSING THE priter WINDOWS. I dont want to close the BROWSER!  
                return false;

            });
        });
    </script>

where can i call the php function insert();

3
  • this should help: stackoverflow.com/questions/5984545/… Commented Feb 4, 2013 at 19:30
  • 1
    JavaScript is client side. PHP is server side. This is not possible without an ajax call. Commented Feb 4, 2013 at 19:30
  • 1
    "POS" - point of sale, or piece of s***? " i would like to call a function after the windows be closed from printing" . Can you try to re-word that? Are you saying you want to print after the window (browser) has been closed? Where are you trying to insert() something? Please edit your question... Commented Feb 4, 2013 at 19:30

2 Answers 2

0

You can't call a PHP function since it's on the sever and your JavaScript code is on the client. You can navigate to a PHP containing that function or make an AJAX call to that page.

Navigating via Javascript would be:

document.location = "yourpage.php"
Sign up to request clarification or add additional context in comments.

1 Comment

You should have some JavaScript in the destination page close the window once it loads.
0

You cannot call PHP functions in the classic sense with Javascript. PHP code is run on the server, while Javascript code is executed in the user's browser window. What you can do however is use a technology called AJAX to send a request back to your server. Using HTTP methods you could initiate a PHP script that returns information back to your Javascript code also over HTTP.

2 Comments

its works :-) but i dot know where can i put in so that call if the script runs to the end. If i insert on wrong place call every time as i relode the page
I call like alert ("<? echo inserPHP(); ?> "); like this i can start the php function. The only one problem is i want to have a popup windows fro ask to insert and if click OK than iserting if No than just close the windows.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.