php-服务器端查询后如何等待客户端的输入?

为了合并一些sql调用,我尝试对服务器进行一次查询,然后让客户端遍历每个结果.需要注意的是,在处理下一个结果之前,我需要等待用户输入.这可能吗?

我有一个类似于以下的jquery调用

$.post('functions/file_functions.PHP', {type: 'test', f: 'load'}, function(data) {
    if (data.success) {
        $.each(data.files, function() {

            // Can I wait for user input at this point and then process the next
            // file after a users interaction (e.g. a button click)?

        });
    }
}, "json");

解决方法:

我将对我的评论进行一些扩展,并希望使它成为一个有用的答案. JavaScript是单线程的,因此在等待其他事件(例如,被单击的元素)发生时,无法阻止函数的执行.相反,您可以做的是,当AJAX POST请求成功返回时,将文件列表存储到数组中,然后使用单独的click事件处理程序来循环浏览它们(我假设每次单击都获得一个文件).

代码可能看起来像这样:

$(function() {
    var files, index = 0;

    $.post('functions/file_functions.PHP', {type: 'test', f: 'load'}, function(data) {
        if (data.success) {
            files = data.files;
        }
    }, "json");

    $('.mybutton').click(function() {
        if(files) {
            var file = files[index++];
            // do something with the current file
        }
    });

});

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...