I want to retrieve data from database and it's display in the div tag with separate line.
This is my data in database
I want to display like this
var prodid = $("#prod_id").val(); var url = "lib/function.php?type=getProductDetails"; $.ajax({ method:"POST", url:url, data:{prodid:prodid}, dataType:"json", success:function (result) { $("#prod_desc").html(result.prod_desc); }, error:function (eobj, etxt, err) { console.log(etxt); } });
this is the division
<div id='prod_desc'> display all data as a list here </div>
I assume from your question that your response is a string. We can use data
as an example string variable.
Use let dataArray = data.split("|")
. Then you will have an array with following values ["Camera:25MP", "Memory:32GB", "Battery: 3400mAh"...]
So dataArray[0]
will be "Camera:25MP"
, dataArray[1]
will be "Memory: 32GB"
etc.
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.