• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 546
  • Last Modified:

call php function in javascript

Hi,
can some one tell me how do i call a php function in a javascript code.
i need thisn very badly
thanks
bobbie
0
tn_bobbie
Asked:
tn_bobbie
  • 6
  • 5
  • 4
  • +3
1 Solution
 
tn_bobbieAuthor Commented:
plz help me
0
 
ZvonkoSystems architectCommented:
php is server side and javascript is client side.
They can only talk to each other by passing text to other side, but never invoke anything from opposite side directly.

Sorry.

0
 
tn_bobbieAuthor Commented:
But there must be a round about way atleast.
plz d help me
tx
bobbie
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
thirdCommented:
tn_bobbie,

  Zvonko is right. but if you can tell us what do you want to achieve then probably we can formulate another way than what you think.


regards,

third ;-)
0
 
tn_bobbieAuthor Commented:
hi ,
thanks for the response.
i'm actually rying to get the meta tags & description from a site whose url is mentioned by a user.
Presently i have a submit button which goes to next php page ,gets  the details & the populate the text areas with the details &the submoit the page to put details in the DB.
I now have 2 navigations(one to get the meta details & one to put in the DB).
But i want to restirct this  to only one.
so i have to actually call that php function in "on change" event of the corresponding text box(where the url is entered).
this is my goal.
so i wanted to call the php function in the javascript.
plz help me.
or can i get the meta details using the javascript?
thanks
bobbie
0
 
neongrauCommented:
hi!

heres a basic strategy:

i recommend using a hidden iframe.

put a "get meta" button to your form. when pushing that button change the formaction's to your php-page that processes your needed meta information and the target to that hidden iframe.

there you can use all php functionality you'll need. at your php-pages end, create a javascript that fills that iframes parent.form with all collected information.

that should work (i've done almost the same using active server pages)

~neongrau
0
 
tn_bobbieAuthor Commented:
is there any possibility of getting these meta info using javascript
0
 
neongrauCommented:
no, not javascript alone.

and thats because of security reasons.
the meta informations you want to access aren't from the same server your javascript resides.

parsing those would be easily possible but you need to read that pages source code. and that is something a browsers won't and shouldn't let you do.

(you wouldn't be amused if microsoft.com would read the other pages you're surfing on while running e.g. windowsupdate.com ;-))

so you need to load that pages source using a server-side side script (normally reading the first 20 lines should be enough to save bandwidth and time).
0
 
neongrauCommented:
no, not javascript alone.

and thats because of security reasons.
the meta informations you want to access aren't from the same server your javascript resides.

parsing those would be easily possible but you need to read that pages source code. and that is something a browsers won't and shouldn't let you do.

(you wouldn't be amused if microsoft.com would read the other pages you're surfing on while running e.g. windowsupdate.com ;-))

so you need to load that pages source using a server-side side script (normally reading the first 20 lines should be enough to save bandwidth and time).
0
 
tn_bobbieAuthor Commented:
is there any possibility of getting these meta info using javascript
0
 
neongrauCommented:
hehe, seems we both reloaded the page  *g*
0
 
GumboCommented:
Try something like this:

<script type="text/javascript">
  document.write('<script type="text/php" scr="my.php">myphpFunction();</script>');
  document.write('<script language="php" scr="my.php">myphpFunction();</script>');
</script>
0
 
Michel PlungjanIT ExpertCommented:
Gumbo: huh???
0
 
GumboCommented:
You cannot call it directly from a javascript-script code, but you can call it in the HTML code with:

        <script type="text/php" scr="my.php">myphpFunction();</script>
or
        <script language="php" scr="my.php">myphpFunction();</script>
0
 
GumboCommented:
Oh, typing error. It has to be 'src' not 'scr'.
0
 
Michel PlungjanIT ExpertCommented:
What browsers support php as scripting language?
0
 
GumboCommented:
I think nearly all, just try it out.
0
 
Michel PlungjanIT ExpertCommented:
??? What do you mean - I know of no browser that supports client side php as scripting language
0
 
tn_bobbieAuthor Commented:
thanks a lot gumbo
0
 
neongrauCommented:
this is no client side scripting but server side.
it's looking somehow confusing but its nothing more than a .shtml page with an alternate (not recommendable) writing of:

<?
require("myphp.php");
myphpFunction();
?>

if gumbos answer is correct than i think we totally misunderstood the whole question. ;-)
0
 
Michel PlungjanIT ExpertCommented:
I do believe we did...
The page that hits the browser no longer has any php in it and the script tags are gone too
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 6
  • 5
  • 4
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now