Calling Php To Other Script!

Discussion in 'PHP' started by bartolay13, Nov 3, 2007.

  1. #1
    hello,

    I just want to ask how to call a php function through JavaScript Events..
    for example:
    <a href=\"#\" onmouseover="phpfunction();">
    PHP:
    thank you... :)
     
    bartolay13, Nov 3, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You can't.

    Javascript runs on the client's browser, and PHP runs on the server.
     
    nico_swd, Nov 3, 2007 IP
  3. brendandonhue

    brendandonhue Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    brendandonhue, Nov 3, 2007 IP
  4. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #4
    is there a best way or the simplest way of doing this?? not going through xml?
     
    bartolay13, Nov 3, 2007 IP
  5. e96

    e96 Active Member

    Messages:
    299
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    80
    #5
    well, one possibility is to do something like
    
    onmouseover="window.location.href='myScriptPage.php?shouldIDoPHPFunction=1' "
    
    Code (markup):
    then in the myScriptPage.php
    do something like
    if ($_GET['shouldIDoPHPFunction']== 1)
    //run the php script.  
    
    Code (markup):
    That's the only workaround I can think of. You could of course call the same page rather than another page (myScriptPage.php). However, it sounds like you're trying to do something counterintuitive since as someone else said php is server side and javascript is client side--therefore, no matter what, you are going to need to send a server requrest to do a php function .
     
    e96, Nov 3, 2007 IP
  6. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You dont need to actually return XML.

    Just return plain text if you like and do whatever you need with it.

    Good Luck!
     
    tonybogs, Nov 3, 2007 IP
  7. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #7
    ah ok, ive think of that, thanks...
    wat about
    <body onunload="phpfunction()">

    i just want to alter something in the mysql db, whenever a user closes the page.
     
    bartolay13, Nov 3, 2007 IP
  8. Fash

    Fash Peon

    Messages:
    37
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You.. can't.. You're going to have to integrate JavaScript or something like it in order to control client data that way.
     
    Fash, Nov 3, 2007 IP
  9. brendandonhue

    brendandonhue Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    As above, this is done with XMLHttpRequest.
     
    brendandonhue, Nov 3, 2007 IP
  10. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #10
    "You cant call server side PHP functions with client side javascript code"-nico told it.If u want to perform certain server side work on any events then the best way is to use AJAX(XMLHttpRequest).just send the request to a server side PHP script and do the work in that script.
     
    coderbari, Nov 3, 2007 IP
  11. madmax728

    madmax728 Banned

    Messages:
    620
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #11
    madmax728, Nov 4, 2007 IP
  12. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #12
    whoa... that solved my problem..

    e96

    passing parameters using js to other page.. thanks
     
    bartolay13, Nov 4, 2007 IP