onclick函数在chrome中不起作用


onclick function not working in chrome

我想设置一个onclick函数,当有人点击它时,我想ajax调用并获取数据并在div中填充,但onclick在chrome中不起作用。在firefox中,它工作得很好,但我不知道为什么它不工作。任何暗示。

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

它是一个对象数组。如果您在某个时刻调用json_decode($data)。

你应该能够想出如何把它放在桌子上。

如果你想在Javascript中循环,可以试试这样的方法。

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

这是SO之前关于使用Javascript循环的讨论。

您需要将$data回显到您的ajax调用中。在您的Javascript中,尝试将数据写入控制台日志。但现在的问题不是如何在Javascript中循环遍历数组,而是如何设置和ajax调用返回json的php应用程序。你可能应该问这个问题。

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"]);
    }
}