2015-06-14 41 views
0

我得到一个回应,但作为一个数字。我怎样才能得到实际的文本名称jquery ajax点击将一个数字传递给一个php文件。需要jquery传递一个文本回复

echo "<td><a href='#' class='js-load-more' data-playername='" 
.($players['first_name'])."'>".($players['first_name'])." ". 
($players['last_name'])."</a></td>"; 

$(document).ready(function() { 
    $(".js-load-more").click(function() { 
     var name = $(this).data('playername'); 
     $.ajax({ 
      url: '/test2.php', 
      type: 'GET', 
      cache: 'false', 
      data: 'name', 
      success: function (data) { 
       $('#info').html(data); 
      }, 
     }); 
    }); 
}); 

RETURNS A NUMBER“1”。为什么不是一个名字?:

<?php 
    $test = isset($_GET['name']); 
    echo $test; 
?> 

回答

0

因为isset()回报boolean值。

isset($_GET['name']); // returns true or false 

$_GET['name']; // returns the playername or undefined index 
0

试试这个:

$test = isset($_GET['name']) ? $_GET['name'] : ''; 
echo $test; 
相关问题