DOM解析器使用jquery ajax调用

I have a quite complicated problem: I use the PHP Simple HTML DOM Parser to fetch some price data from different webshops. The data is shown on my website. The problem is that I need data from about 10 shops with about each 50 products. So about 500 links all in all. The Links are retrieved from an CSV. I want it like this: Open the csv -> retrieve the link -> parse the price data from the link -> show it on the website

My first try was this:

var file = 'shops.csv';

        Papa.parse(file, {
          delimiter: ";",
          download: true,
          header: false,
          dynamicTyping: true,
          complete: function(results) {
            $.each(results.data, function(i, item){
                $.ajax({
                    type: 'POST',
                    url: "parser.php",
                    data: {url:item[4]},
                    success: function(data,status){
                        if(data){
                            var output = '<a href="'+item[4]+'" target="_blank">' + data +'</a>';
                            $('table tbody tr[data="'+item[1]+item[3]+'"] td').append(output);
                        }
                    },
                    async:true
                });
            });
          }
        }); 

Now all links are parsed synchronous which crashes the server. When the ajax call is done asynchronous the data is only shown when the last call is done. The perfect way should be step by step... get the link -> get the price -> show the price -> next.

duanmeng3573
duanmeng3573 别客气。最好放置handleNext(index+1);不是在成功处理程序的最后,而是在完整的处理程序中。即使一个ajax请求导致错误,它也将有助于继续迭代。
大约 6 年之前 回复
duanaozhong0696
duanaozhong0696 看货,非常感谢。比我想象的容易;)
大约 6 年之前 回复
doufu5521
doufu5521 ......然后一步一步地做。在成功处理程序中调用下一次迭代。像这样的东西。
大约 6 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐