-2

I want to set a onclick function and when some one click on it i want to ajax call and get data and populate in div but onclick is not working in chrome .In firefox it's working fine but i don't know why it is not working .any suggestiong .

2 Answers2

1
foreach ($data as $item) {
    echo $item->item_title;
}

It is an array of objects. If you at some point call json_decode($data).

You should be able to figure out how to put it in a table.

If you want to loop through in Javascript, try something like this.

for (var item in data) {
  alert(item.item_title);
}

Here's a previous SO discussion on looping with Javascript.

You need to be echoing out that $data to your ajax call. In your Javascript try and write data to your console log. But now your question isn't how do you loop through an array in Javascript, but rather, how to setup and ajax call to a php application that's returning json. You probably should ask that question instead.

Community
  • 1
  • 1
Halfstop
  • 1,710
  • 17
  • 34
0
var ajax_response = someData;
if(ajax_response !=""){
    for(var i=0; i<ajax_response.length; i++){
        console.log(ajax_response[i]["user_id"]);
        console.log(ajax_response[i]["item_title"]);
        console.log(ajax_response[i]["item_price"]);
        console.log(ajax_response[i]["item_description"]);
        console.log(ajax_response[i]["date_time"]);
    }
}
Muhammad Husnain Tahir
  • 1,009
  • 1
  • 15
  • 28