weixin_33744854 2016-05-29 08:58 采纳率: 0%
浏览 13

如何使用ajax获取php var

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条回答 默认 最新

  • weixin_33736832 2016-05-29 09:04
    关注

    Your javascript has html link, but you are trying to call php file:

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

    Change it to

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

报告相同问题?