【发布时间】:2014-05-08 23:45:07
【问题描述】:
我有一个 .getJSON() 函数,它在按钮单击时触发(来自 DB 的随机记录)。它适用于桌面设备,但在移动设备上只能使用一次。然后它继续提供相同的记录。我猜它甚至不会对 php 进行 AJAX 调用,因为每次请求 php 时,random.php 文件都会创建一个 JSON 文件.. 并且在移动请求上,不会创建 JSON 文件..
jQuery 部分:
$("#random_post").click(function(){
$.getJSON("random.php",function(result){
$.each(result, function(i, field){
$("#selected-name").text("Name: ".concat(field.name));
$("#selected-link").text("Link: ".concat(field.link));
$("#selected-date").text("Date: ".concat(field.date));
$("#selected-content").text("Content: ".concat(field.content));
$("#selected-video").text("Video: ".concat(field.video));
});
});
});
PHP交付部分是通常的:
echo json_encode($data);
$fp = fopen('results2.json', 'w');
fwrite($fp, json_encode($data));
fclose($fp);
按钮是http://raigle.com/a.php的随机帖子
【问题讨论】:
-
@Pinch 我应该在哪里以及如何做到这一点?
-
只是一个建议,你的
$("#random_post").click应该return false -
@jeremy 我玩过,没有效果