Jquery load() and PHP variables

前端 未结 6 846
死守一世寂寞
死守一世寂寞 2020-12-03 00:29

If I load a PHP page with Jquery .load(file.php), can the included file use the php variables that were defined on the page that called the load()?

6条回答
  •  死守一世寂寞
    2020-12-03 00:44

    Yes, use the data parameter, see http://api.jquery.com/load/:

    $('#someelement').load(
        "test.php", 
        {
            'key1': '',
            'key2': ''
        } 
    );
    

    The parameters are posted to the file test.php and are accessible as:

    $_POST['key1']
    $_POST['key2']
    

提交回复
热议问题