简体   繁体   中英

print another page from the current page passing a value

hi i need to validate the next page before printing it ... what i did is i used i frame in the first page and called the page i needed to print but it fired the query in the first page which should have been fire in the second page after the submission or click of the button ...

so i need to fire the php function after the button click which calls a function in javascript how should i do this?

could anybody help me...

Okay, I am not familiar with your level of PHP knowledge, so I will start with some basics:

PHP is a server-side scripting language. It compiles in real-time when a page is requested. The server processes the HTML and PHP and serves an HTML only page to the browser. You cannot execute PHP code on the client side. There is no way to get PHP code running at the time of a button press without the use of AJAX. You could use AJAZ to make a request to the server at the press of the button and fill the iFrame with the output.

Hope that helps.

so i need to fire the php function after the button click which calls a function in javascript how should i do this?

I am not quite clear on why you would need to do this but here it goes...

In the button click handler you want to make an AJAX call. I use jQuery but you can use whatever framework or XMLHttpRequest function you wish.

<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
    function ButtonClickHanlder( e ) {
        // Prevent the button from doing something it's normal functions(ie submit form if it is a submit)
        e.preventDefault();
        // Make AJAX Call
        $.post("test.php", { call: "callMe" },
            function(data){
                alert("Data Loaded: " + data);
            }
        );
    }

    $(function(){

        $('#clicker').click(ButtonClickHanlder);
    });
    </script>
</head>

<body>
<a id="clicker" href="#">test</a>

</body>
</html>

Reference: http://docs.jquery.com/Ajax

The test.php page

<?php

if(isset($_POST['call']) && $_POST['call'] == 'callMe') {
    callMe();
}

function callMe() {
   echo "I am a php function. You rang?";
}

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM