2015-11-26 72 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); 
     });   
});