I'm using jQuery Ajax to send request and get response on success/failure.
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)
. 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. How can I split this values.
使用php内部函数json_encode
In php you can emit json using json_encode
. In jQuery's success function you can parse json and use as
success:function(data)
{
//echo data;
var parsedData = $.parseJSON(data);
// use it by index numbers as
var first_element = parsedData[0];
// ans so on..
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.