1

我有一个这样的 jquery 帖子

<script type = "text/javascript" >
$(document).ready(function() {
    $('#find').click(function() {
        var amount = $('#amount').val();
        $.ajax({
            type: "POST",
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            url: "questions.php",
            data: {
                'amount': amount
            },
            success: function(data) {
                $('#results').show();
                $('#results').html(data);
            }
        });
    });
});
</script>

并且成功的数据有一个这样的php数组

Array ( [0] => mpla mpla [1] => mplum mplum ....

如何在屏幕上显示项目之前使用 jquery 或 javascript 获取项目。

我只想要链接的文本

mpla mpla -->that is a link

mplum mplum -->that is a link too
4

2 回答 2

1

在你的 php.ini 文件中。做一个:

echo json_encode( YOUR ARRAY );

将您的 jQuery $.ajax 设置数据类型设置为 json。

在您的成功功能中,您现在可以使用

success : function(data){
    // data is now a javascript array
    var st = data.join(" ");
}
于 2012-10-15T17:35:51.370 回答
0

首先,您需要将其转换为 json 格式...

然后您可以使用$.each循环访问它们

$.each(data , function(i , value){

    console.log( 'Index - ' + i + ' = ' + value );
});
于 2012-10-15T17:35:03.210 回答