使用 AJAX 监听来自服务器的多条消息:JQuery
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回到起点。 写下您真正想做的事情的请求。 您可能会发现您需要采用轮询等方法,或者可能使用 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.