fizampou
fizampou

Reputation: 717

jquery post and response manipulation

i have a jquery post like that

<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>

and data on success has a a php array like that

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

how can i get the items using jquery or javascript before presenting them on screen.

i want the text only like links

mpla mpla -->that is a link

mplum mplum -->that is a link too

Upvotes: 1

Views: 151

Answers (2)

Niels
Niels

Reputation: 49919

In your php. Do a:

echo json_encode( YOUR ARRAY );

Set your jQuery $.ajax settings datatype to json.

In you success function you can now use

success : function(data){
    // data is now a javascript array
    var st = data.join(" ");
}

Upvotes: 1

Sushanth --
Sushanth --

Reputation: 55740

First you need to convert this into json format...

Then You can access them using the $.each loop

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

    console.log( 'Index - ' + i + ' = ' + value );
});

Upvotes: 0

Related Questions