calling a php function in javascript

坚强是说给别人听的谎言 提交于 2019-12-01 01:44:06

There is only one way to call a php function after the page is loaded:

1.ajax:

function callPHP() {
    $.ajax ({
        url: "yourPageName.php",
        data: { action : assign }, //optional
        success: function( result ) {
            //do something after you receive the result
        }
    }

in your PHP, write

if ($_POST["action"] == "assign")
{
    assign(your parameters); //You need to put the parameters you want to pass in
                             //the data field of the ajax call, and use $_POST[]
                             //to get them 
}

There are many great guides on the internet. I will however suggest you get too know JQuery. It will help you on your learning curve.

function ajaxCall(){
$.ajax({
    type: "GET",
    url: "scripts/on/serverside.php"
   });
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!