I am developing a hybrid application using intel XDK. In the application, I use ajax request for my PHP server. The server will respond with json data.
This is my json example from the server.
[{
"id":"11",
"user_id":"8000",
"product":"Shoes A",
"quantity":"1",
"date_open":"2015-01-04",
"paid":"1",
"harvested":"",
"reinvest":null,
"profit":null,
"investment":"3000"
},
{
"id":"12",
"user_id":"8000",
"product":"Shoes B",
"quantity":"1",
"date_open":"2015-03-01",
"paid":"1",
"harvested":"",
"reinvest":null,
"profit":null,
"investment":"1500"
}]
The amount of product per user is different here, some have no product, some have 1, 2 ... 10, etc. products. Thus, depending on how much the userβs product is , whatβs best to display them . So that all data and elements are organized and display well with the image when the page loads.
Should display automatically:
| product image | product name | date | profit | investments
What should be the html page / css style setting? Or anything I need to know about this.
PHP. foreach . , .
:
foreach(products as product){
?>
<div class="img"></div>
<div class="productname">echo product['product'];</div>
<?
}
, , html, , PHP. .
: ajax :
$("button").click(function(){
$.ajax({
type: 'POST',
url: "http://www.sample.com/app/user-data.php",
crossDomain: true,
dataType: 'json',
data: { user_token: user_token },
success: function(data, status, jqXHR) {
console.log(JSON.stringify(data));
},
error: function(xhr, ajaxOptions, thrownError) {
alert(ajaxOptions + " " + thrownError);
}
});
});