Run PHP code when user clicks link and pass variables

前端 未结 2 850
难免孤独
难免孤独 2021-01-25 05:37

I need to run a PHP code from external server when user clicks a link. Link can\'t lead directly to PHP file so I guess I need to use AJAX/jQuery to run the PHP? But how can I d

2条回答
  •  自闭症患者
    2021-01-25 06:24

    You can do this with an ajax request too. The basic idea is:

    1. Send ajax request to runcode.html
    2. Configure another AJAX to trigger from that page

    Considering, this as the markup

    Test
    

    JS

    $("#link").on("click", function() {
        $.get("runcode.html", { "id" : ID }, function(data) {
           //on success 
        });
        return false; //stop the navigation 
    });
    

提交回复
热议问题