Calling a php function using ajax/javascript

前端 未结 6 1294
庸人自扰
庸人自扰 2021-01-21 16:21

Ok guys I know this question has been asked before but I am very new to PHP and JavaScript and hadn\'t even heard of ajax until i started looking for an answer to this question

6条回答
  •  无人共我
    2021-01-21 16:59

    Take a look at the .get() documentation. You're using it incorrectly.

    You should be passing data (optional) and handling the data that gets returned, at a minimum:

    $.get("backend.php",
        {
            // data passed to backend.php goes here in 
            //
            // name: value
            //
            // format. OR you can leave it blank.
        }, function(data) {
            // data is the return value of backend.php
            // process data here
        }
    );
    

    If you pass data, you can retrieve it on backend.php using $_GET. In this case:

    $_GET['name'];
    

提交回复
热议问题