I am trying to print out some information (A list that has sub-lists in it) from the database and I am trying to use JQuery to do this.
I am trying to call certain methods on the server and then get the information that I will then format and display to the user.
for exapmle if I have this function
<?php
function find_all($id)
{
$result=Name::find_names_byid($id)
return $result; //where result is an array like array[][] including the name and the id
}
?>
How can I retrieve this using Javascript, and how can I use what I get back in order to process it? I am sure it is something very obvious, but I simply can’t figure it out.
I tried to use $.get but it got me nowhere.
What you are trying to do is called AJAX 🙂
I recommend some more reading about this subject because an answer to your question would be pretty extensive… You could start with this article which is also linked on Jquery.com: Article
If you want to pass structured data like for example an array of strings instead of pure text as in the example, you should encode your data into JSON (google it) with json_encode($data).
On the javascript side you can set the datatype of the AJAX response to ‘json’:
This way, your callback function retrieves an javascript object/array which contains the data the php script returned.