【问题标题】:i need to return an entire html page using an ajax call我需要使用 ajax 调用返回整个 html 页面
【发布时间】:2014-02-21 08:43:54
【问题描述】:

我需要返回这个页面的内容http://service.semanticproxy.com/processurl/ftfu27m3k66dvc3r43bzfneh/html/http://www.smallbiztechnology.com/archive/2013/12/why-creating-a-digital-storefront-is-crucial-for-your-small-business.html但是当我调用这个函数时

function getResult() {
            var url="http://service.semanticproxy.com/processurl/ftfu27m3k66dvc3r43bzfneh/html/http://www.smallbiztechnology.com/archive/2013/12/why-creating-a-digital-storefront-is-crucial-for-your-small-business.html";
            $.ajax({
                cache: true,
                url: url,
                success: function (result) {
                    alert(result);
                }
            });
        }

我在萤火虫中得到了这个:

segment.min.js(线 1) 获取http://service.semanticproxy.com/processurl/ftfu...orefront-is-crucial-for-your-small-business.html 200 OK 379msA。

知道如何获取该页面的内容吗?

【问题讨论】:

  • 您遇到了同源策略。查看跨域 AJAX。
  • 该 URL 不允许来自其他域的请求,您需要在您的服务器上托管自己的代理脚本,该脚本会下载并返回 URL 的内容。

标签: javascript ajax opencalais


【解决方案1】:

此代码对您不起作用。原因是您尝试检索的 html 页面不是有效的 JAVASCRIPT 文件(而且您也不能使用 jsonp,因为它没有返回任何 json 字符串。)

你的解决方案是使用服务器脚本(如php:

<?Php print file_get_contents(url); ?> 

)。

或者 - 如果网站是您的,请根据请求添加对脚本的响应。

【讨论】:

    猜你喜欢
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-03-07
    • 2014-06-19
    • 1970-01-01
    • 2021-07-26
    • 1970-01-01
    相关资源
    最近更新 更多