Calling a php function using ajax/javascript

前端 未结 6 1334
庸人自扰
庸人自扰 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 17:03

    It does nothing becuase you don't do anything with the result. My guess is that in the example you took, it does some work and doesn't show anything to the user. So if you just had some stuff you wanted to run on the server without returning any output to the user, you could simply do that, and it would work.

    Example from jQuery's .get() documentation

    What you do:

    Example: Request the test.php page, but ignore the return results.

    $.get("test.php");
    

    What you want to do:

    Example: Alert out the results from requesting test.php (HTML or XML, depending on what was returned).

    $.get("test.php", function(data){
        alert("Data Loaded: " + data);
    });
    

提交回复
热议问题