Running PHP inside a javascript function?
Discussion
I have the following code which executes when a user prints a page (It's set as the background in a CSS Style Sheet in the @print section).
What that does is insert a record into my MySQL database logging the fact that a record has been printed.
Is there a way to get JS, a client side app to tell PHP, a server side app to launch a php script?
I need logit.php to fire off inside the print()function rather than during an onload fucntion.
Any help or pointers greatly appreciated.
$BGImage = background-image:url(logit.php?RectNo=$RectNo&DBForLogit=db04)";
What that does is insert a record into my MySQL database logging the fact that a record has been printed.
Is there a way to get JS, a client side app to tell PHP, a server side app to launch a php script?
I need logit.php to fire off inside the print()function rather than during an onload fucntion.
Any help or pointers greatly appreciated.
I can't take all the credit but it works very well Unfortunately I'm moving over to PDF creation on the fly and the class that I use doesn't currently support the background-image css command
I only use PHP and JS, I don't really have time to go learn another language for one task, I just need to get JS to tell my script to run. I can pass it PHP variables but I don't know how to say the following
{{{
function printMe() {
print ()
./logit.php?RectNo=$RectNo&DBForLogit=db04
}
}}}
Can't be that difficult, surely I'm only calling a url effectively??
I only use PHP and JS, I don't really have time to go learn another language for one task, I just need to get JS to tell my script to run. I can pass it PHP variables but I don't know how to say the following
{{{
function printMe() {
print ()
./logit.php?RectNo=$RectNo&DBForLogit=db04
}
}}}
Can't be that difficult, surely I'm only calling a url effectively??
BliarOut said:
Can't be that difficult, surely
Like anything, not if you know how jQuery and Prototype are not new languages per se, they are javascript, although they do have a particular syntax.
Put it this way - they make using javascript easy rather than a PITA, especially when it comes to browser compatibility.
Should do what you want:
<html>
<head>
<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript">
function printMe ()
{
print ();
$.ajax({
url: '/logit.php?RectNo=$RectNo&DBForLogit=db04',
success: function(data) {
alert('Query Complete');
}
});
}
</script>
</head>
<body>
...
</body>
</html>
Edited by sonic_2k_uk on Tuesday 10th August 18:08
-DeaDLocK- said:
I always thought jQuery alone was worth a fortune (some of the best things really are free!), but jQuery coupled with Ajax is in a whole different league of usefulness!
Yeah it completely changed the face of the internet IMO.BliarOut said:
Well I couldn't quite get that to work, but it pointed me in the right direction
I ended up using a xmlhttp request which means I can pass php variables into js and then use them in my new function
I can see how that's going to be very useful when I polish my app
Glad you got it working!I ended up using a xmlhttp request which means I can pass php variables into js and then use them in my new function
I can see how that's going to be very useful when I polish my app
AJAX uses the xmlhttp object, but have you tried it in multiple browsers if you've coded it manually?
jQuery will use the correct request object based upon your browser. It saves you alot of work and standardises everything.
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff