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 .
Asked
Active
Viewed 91 times
-2
-
Are you returning the `$data`? – Andrei Oct 30 '15 at 15:32
-
ajax call ,............. – Asif Gujjar Oct 30 '15 at 15:41
-
So what's your point? You still need to either return or echo some date. Your choise. – Andrei Oct 30 '15 at 15:59
-
can you answer me??? – Asif Gujjar Nov 04 '15 at 14:55
2 Answers
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.
-
I am using ajax call and get response using json object and i want to loop json object .not php loop – Asif Gujjar Oct 30 '15 at 15:20
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