Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
21
rated 0 times [  28] [ 7]  / answers: 1 / hits: 12501  / 11 Years ago, sat, december 7, 2013, 12:00:00

I am making a web app, where I want to provide a search function. I am sending the searched name with an ajax request, and i want to pull the records of that particular person. But since there are many details that are to be displayed, I am finding it difficult to get the response. (I am not able to get more than one response at a time)



I want to know, if there is a way to get multiple responses for a single request, or a way to send all my variables in the target PHP file to the requesting javascript file as an array or something.



Thank you. If this question is asked before, please provide the link.


More From » php

 Answers
0

Use JSON as the datatype to communicate between PHP(Backend) and Javascript(Frontend). Example:



PHP



<? 
$person = array(name=>Jon Skeet,Reputation=>Infinitely Increasing);
header(Content-Type: application/json);
echo json_encode($person);
?>


Javascript/jQuery



$.ajax({
url: your_script.php,
dataType: JSON

}).success(function(person) {
alert(person.name) //alerts Jon Skeet
});

[#49762] Friday, December 6, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andreguym

Total Points: 125
Total Questions: 112
Total Answers: 103

Location: Wallis and Futuna
Member since Tue, Mar 30, 2021
3 Years ago
;