开发者

How to call a PHP function from JS that is invoked when clicking a link?

I have this test page:

http://www.comehike.com/hikes/uncancel_hike.php?hike_id=30

When click开发者_如何学编程ing "yes" I am able to get the JavaScript function invoked named uncancelHike, but I don't really know how to call the PHP function.

I do import a php script with a function named uncancelHike() but I am not certain how to call it from that Javascript.

I do use YUI in the code, but not sure if I should be using it here, or this is something much simpler.


You need to use AJAX here, this tutorial should helpful for you:

Beginning AJAX Using The YUI Library


Ajax is not the answer of every thing :D

<?php

    if(isset($_POST['but1'])){
        t1();
    }elseif(isset($_POST['but2'])){
        t2();
    }


    function t1()
    {
       echo "The t1 function is called.";
    }
    function t2()
    {
       echo "The t2 function is called.";
    }

?>

<html>
<head>
<title>Test</title>
</head>
<body>
<form action="test.php" method="POST">
<input type="submit" value="Click1" name="but1">
<input type="submit" value="Click2" name="but2">
</form>
</body>
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜