![]() |
How do you call a PHP script from Javascript ?
I need to call a PHP Script from a Javascript segment of code. I also need the Javascript to stop it's execution while the PHP script does it job. Once the PHP script is done the Javascript must continue where it was.
Is such a thing possible. If it's ... how. (I know it's possible with sockets, but seems too much trouble that way...) Thanks |
PHP is server-side and Javascript is client-side, which means the two will not be able to function together.
|
Quote:
|
No it's possible ... in fact it's even easy to do it ...
in Javascript : window.navigate("http://yourPHPScript.php"); and that will do ... but in my case I'm doing it in the onBeforeUnload event. Since I call a other page while the browser is closing the PHP script never receive the info and create an empty record in my DB. So i would need something that loops so the onbeforeUnload don't finish until the php script is done. Basically I need a fucntion that block Javascript execution until the new page isn't completly loaded |
Well, if you're going to a separate page entirely... what you could do is split your function into two new functions, so the first half gets done... then it calls the php script, and then the php script runs a "onLoad" so that it refers back to the original document and the second half of your javascript.
|
try using an iframe
|
lots of ways you can get shit like that to work... usually better to stuff in php first then pass to javascript works fine for me all the time... what exactly are you trying to do?
|
you can call an update script from a page in java anytime you want with a little trick
put an image on a page like this < img src=whatever height=1 width =1 name="trick" > in a java script you can do the following trick.src = whatever.php hope this helps. |
Quote:
|
Quote:
I dunno... just seems like having javascript do stuff when they close their browser will result in a LOT of lost data and won't save much if anything on serve load. |
easy way to do it is at the top of every script include a small php inc file that just monitors the ref, dt, ip etc inserting to your db... you can also append what they clicked on in the uri so you can track it that way as well... no need for javascript.
obviously if there is no more activity, they've closed the browser, because up until that point you've monitored where they are going in the site :) |
Quote:
Might represent a good saving (Processing power) if my site gets lot of traffic. |
[QUOTE=naitirps]easy way to do it is at the top of every script include a small php inc file that just monitors the ref, dt, ip etc inserting to your db... you can also append what they clicked on in the uri so you can track it that way as well... no need for javascript.
QUOTE] I know I could do this like you wrote, but it will result in way to much connection to my database... |
so dump to flatfile, and update hourly to your db then
or do it solely in xml... |
Quote:
Good luck with that -lol. |
cookies is he answer
|
All times are GMT -7. The time now is 02:40 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123