Running PHP inside a javascript function?

Running PHP inside a javascript function?

Author
Discussion

BliarOut

Original Poster:

72,857 posts

241 months

Tuesday 10th August 2010
quotequote all
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).


$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.

BliarOut

Original Poster:

72,857 posts

241 months

Tuesday 10th August 2010
quotequote all
I can't take all the credit but it works very well biggrin 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 weeping

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 biggrin 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 biggrin I'm only calling a url effectively??

BliarOut

Original Poster:

72,857 posts

241 months

Tuesday 10th August 2010
quotequote all
Well I couldn't quite get that to work, but it pointed me in the right direction thumbup

I ended up using a xmlhttp request which means I can pass php variables into js and then use them in my new function biggrin

I can see how that's going to be very useful when I polish my app yes

BliarOut

Original Poster:

72,857 posts

241 months

Tuesday 10th August 2010
quotequote all
Fortunately my script checks the version of the request and uses activex for older versions of IE. It's been a useful exercise as I'll be moving on to storing options for the site in MySQL soon and AJAX could come in handy for that.

It's not such a leap as I thought thumbup