Barney
Barney

Reputation: 1848

Simple AJAX call to return data

So I'm trying to do a simple AJAX call(my first try at it), to return the highest value in a field of a MySQL table. I'm getting the error "Object of class DB_Result could not be converted to string", and I think this is something to do with serialisation?

I tried, after the query: $a = [query here], doing serialize($a), which gave me the output O:9:"DB_Result":1:{s:3:"res";i:0;}

I'm not sure what that means, but all I'm looking to return is an int.

Any help appreciated :)

Upvotes: 0

Views: 54

Answers (1)

JorisW
JorisW

Reputation: 128

Use json_encode in php to encode your db_result

Use following code to retrieve the json result:

$.ajax({
    type: "GET",
    url: "",
    processData: true,
    data: {},
    dataType: "json",
    complete: function(){ },
    success: function() {}
}); 

Upvotes: 1

Related Questions