How to get php var with ajax

时间:2016-05-29 08:58:21

标签: php ajax

I have a html div (with id example) where i want to print php variable $test. My php looks like this:

<?php 

function Test(){
//some action;
return 'Hello World!';
}

$test = Test();
echo $test;

?>

Also i have javascript file :

$.get( "ajax/index.html", function( data ) {
  $( "#example" ).html( data );
});

What's the problem ?

My html file :

...
<script>
function Ajax(){
    $.get( "../Auth/user_save.php", function( data ) {
        $( "#example" ).html( data );});
</script>
<div id = "example"></div>
<input type='submit' onClick='Ajax();'></input>

1 个答案:

答案 0 :(得分:0)

您的javascript包含html个链接,但您尝试拨打php文件:

$.get( "ajax/index.html", function( data ) {
  $( "#example" ).html( data );
});

将其更改为

$.get( "ajax/your_php_file.php", function( data ) {
  $( "#example" ).html( data );
});