[英]How is the result stored in jQuery Ajax data object on success callback
I'm using jQuery Ajax to send request and get response on success/failure. 我正在使用jQuery Ajax发送请求并获得成功/失败的响应。
Server Side 服务器端
I'm using POST to send request to another script that fetches the query results from MySQL array using mysql_fetch_array($query)
. 我正在使用POST将请求发送到另一个脚本,该脚本使用
mysql_fetch_array($query)
从MySQL数组获取查询结果。 When I echo this results, I get to display the string object data. 当我回显此结果时,我将显示字符串对象数据。
$strSQL = "SELECT name from builder";
$query = mysqli_query($con, $strSQL);
while($result = mysqli_fetch_array($query))
{
echo $result["name"];
}
Client Side 客户端
success:function(data)
{
echo data;
}
In the client side, when I try to get the results I use data in success which is a string object in success callback. 在客户端,当我尝试获取结果时,我会成功使用数据,这是成功回调中的字符串对象。
How does the object get stored in data object I have the following doubts 该对象如何存储在数据对象中,我有以下疑问
Addendum 附录
When I fetch query results, I see all values are copied and cannot be separated with split function. 当我获取查询结果时,我看到所有值都已复制并且无法使用split函数分隔。 How can I split this values.
如何拆分这些值。
使用php内部函数json_encode
In php you can emit json using json_encode
. 在php中,您可以使用
json_encode
发出json。 In jQuery's success function you can parse json and use as 在jQuery的成功函数中,您可以解析json并用作
success:function(data)
{
//echo data;
var parsedData = $.parseJSON(data);
// use it by index numbers as
var first_element = parsedData[0];
// ans so on..
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.