PHP file_get_contents x域导致页面加载等待.不能以某种方式异步完成吗


PHP file_get_contents x-domain causes page-load to wait. cant it be done asynchronously somehow?

我需要做两件事。。。

  1. file_get_contents,然后在javascript中使用
  2. file_get_contents,然后在php中使用

源文件的加载导致我的网站加载延迟,所以如果源文件加载缓慢或离线,就会产生可怕的后果。

什么是解决这一问题的好办法或解决方案?

在javascript(使用jquery)中,有两种测试方法。第一个是iframe:

js:

$(document).ready(function() {
    $("#youriframe").attr("src","http://yoururl");
});

正文:

<iframe id="yourframe" src=""></iframe>

或者您通过ajax使用id=yourcointainer 的div

js:

  $(document).ready(function() {
        $.ajax({
            url : 'http://yoururl',                 
            type : 'GET',
            dataType : 'html',
            success: function (result) {                        
                $('#yourcointainer').html(result);
            },
            error: function(){
                $('#yourcointainer').html('request fail');
            }           
        });
    });

正文:

<div id="yourcointainer"></div>

而在PHP中,我找不到一种正确的方法来从请求中获取数据而不等待它本身。