如何在php中获得对单个ajax请求的多个响应 [英] How to get multiple responses to a single ajax request in php

查看:53
本文介绍了如何在php中获得对单个ajax请求的多个响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个Web应用程序,我想在其中提供搜索功能.我正在发送带有ajax请求的搜索名称,并且我想提取该特定人员的记录.但是,由于要显示许多细节,因此我很难获得答复.(我一次只能收到一个以上的回复)

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)

我想知道,是否可以通过单个请求获取多个响应,或者可以将目标PHP文件中的所有变量作为数组或其他内容发送到请求的javascript文件.

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.

推荐答案

使用 JSON 作为数据类型在 PHP (后端)和 Javascript之间进行通信(前端).示例:

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

<? 
$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
});

这篇关于如何在php中获得对单个ajax请求的多个响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆