weixin_33744141 2013-11-08 21:10 采纳率: 0%
浏览 36

jQuery无法从Ajax运行

Guys i have a big problem, I have this jquery (I think) code, this code doesn't works from the ajax, and I don't know why, maybe someone can help me.

function showname(id){
    $.ajax({
       url:'tooltip.php',
       data:{id:id},
       async: false,
       success:function(response)
       {
          // use response for tooltip
          alert(response);
       }
    });
});
}

I put an alert on the php code, and the php code works when I call from url (like http://mysite.com/tooltip.php?id=LNFC without " ' ") that code must return the result of the query done on php code.

Php code

<?php 
$q="SELECT complete_name from mytable where id='".$_REQUEST['id']."'" or die(mysql_error()); 
$result=mysql_query($q,$conection); 
$row=mysql_fetch_assoc($result); 
echo $row['complete_name']; 
?>

Thanks.

  • 写回答

1条回答 默认 最新

  • weixin_33728708 2013-11-08 21:19
    关注

    Try this instead:

    function showname(id){
        $.ajax({
           type:'POST',
           url:'tooltip.php',
           data:{id:id},
           success:function(response) {
              // use response for tooltip
              alert(response);
           },
           error:function(response) {
               alert(response.errorThrown); 
           }
        });
    }
    
    评论

报告相同问题?