使用 AJAX 监听来自服务器的多条消息:JQuery

发布于 2024-07-13 18:14:25 字数 514 浏览 5 评论 0原文

我对 PHP 脚本进行 AJAX 调用,如下所示:

function convertNow(validURL){      
     $.ajax({
       type: "GET",
       url: "main.php",
       data: 'url=' + validURL,
       success: function(msg){
       alert(msg);
       }//function
     });//ajax
}//function convertNow

从上面的内容来看,它所做的就是在最后从 PHP 接收大量文本。 事实上,PHP 脚本所做的是每隔几秒进行大量打印,持续大约一分钟。 我希望实时显示此内容。

我认为问题在于我使用 JQuery 的方式,因为我已经在没有任何 AJAX 的情况下对此进行了测试,并且 PHP 脚本将每个 print_r 实时输出到浏览器! 我只需要复制这个但使用 AJAX。

感谢您的帮助和指导。

I make an AJAX call to a PHP script like so:

function convertNow(validURL){      
     $.ajax({
       type: "GET",
       url: "main.php",
       data: 'url=' + validURL,
       success: function(msg){
       alert(msg);
       }//function
     });//ajax
}//function convertNow

From the above all it does is receive a lot of text from PHP right at then end. In actual fact, what the PHP script is doing is a lot of prints every few seconds for about a minute. I want this to be shown in real time.

I think the problem is the way I am using JQuery because I have tested this without any AJAX and the PHP script outputs each print_r to the browser in real time! I just need to replicate this but using AJAX.

Thank you for any help and guidance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗喜 2024-07-20 18:14:25

回到起点。 写下您真正想做的事情的请求。 您可能会发现您需要采用轮询等方法,或者可能使用 COMET 之类的方法来实现您想要的。

Go back to the start. Write a request with what you actually want to do. You'll probably find that you need to adopt a method such as polling, or maybe use something like COMET to achieve what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文