2015-11-26 69 views
0

我想顯示一些文本已經從一個PHP文件加載並提醒它。問題是沒有任何東西顯示在警告框中。從PHP加載文本和警報 - 什麼都沒有顯示在警報框

JS:

$(document).ready(function(){ 
    $(".col-md-8").load('test.php'); 
    var pgmonth = $('.col-md-8').text(); 
    alert (pgmonth); 
}); 

PHP(test.php的):

<?php 
    echo "Test"; 
?> 

回答

0

原因AJAX(負荷功能)未完成。

$(document).ready(function(){ 
     $(".col-md-8").load('test.php',function(){ 
      var pgmonth = $('.col-md-8').text(); 
      alert (pgmonth); 
     });   
});