Php 将通过ajax返回的数据显示为链接

Php 将通过ajax返回的数据显示为链接,php,html,jquery,Php,Html,Jquery,我通过ajax将“id”和“数据”传递给php 1.$.ajax({//Make the Ajax Request 2. type: "POST", 3. url: "dbtryout2_2.php", 4. data:datastr, 5. success: function(arrayphp) 6. { 7. //her

我通过ajax将“id”和“数据”传递给php

1.$.ajax({//Make the Ajax Request 2. type: "POST", 3. url: "dbtryout2_2.php", 4. data:datastr, 5. success: function(arrayphp) 6. { 7. //here iam displaying the returned data. 8. //I wanna display this data as link 9. //because on clicking on it I 10. //again want to call another php script. 11. $(".searchby .searchlist").append(arrayphp); 12. 13. } 14. }); 15. I have not shown the php code.The code is working well. 16.BUT iam unable to display the data as link.I also want to give the data a "class name". 17.PLEASE if anybody know ...fix this problem 1.$.ajax({//发出ajax请求 2.键入:“POST”, 3.url:“dbtryout2_2.php”, 4.数据:datastr, 5.成功:功能(ArrayHP) 6. { 7//此处显示返回的数据。 8//我想将此数据显示为链接 9//因为点击它我 10//再次要调用另一个php脚本。 11.$(“.searchby.searchlist”).append(arrayphp); 12 13. } 14. }); 15我没有展示php代码。代码运行良好。 16.但我无法将数据显示为链接。我还想为数据指定一个“类名”。 17.如果有人知道……请解决这个问题
如果php返回的数据只是链接的标签,则可以使用以下代码:

$.ajax({//Make the Ajax Request
    type: "POST",
    url: "dbtryout2_2.php",
    data:datastr,
    success: function(arrayphp)
    {
        var link = $('<a href="#" class="my-class">' + arrayphp + '</a>');
        $(".searchby .searchlist").append(link); 

    }
});
$.ajax({//发出ajax请求
类型:“POST”,
url:“dbtryout2_2.php”,
数据:datastr,
成功:功能(ArrayHP)
{
变量链接=$('');
$(“.searchby.searchlist”).append(链接);
}
});

非常感谢兄弟……我在这个问题上被耽搁了三天。你的代码正在工作……不客气。(你可以将我的答案标记为正确,这样其他人也可以使用)。@krasimir看下面我有一些与之相关的问题,如果你直接在javascript中这样做会怎么样。类是否来自php。@krasimir如何从ajax函数外部访问链接类