简体   繁体   English

使用Jquery从URL读取文本文件

[英]Read a text file from the url using Jquery

I am trying to read a text file from the server using the below code. 我正在尝试使用以下代码从服务器读取文本文件。 I am not able to access it but when I just have that text file local then its working fine. 我无法访问它,但是当我只有本地文本文件时,它可以正常工作。 Please let me know what to do 请让我知道该怎么办

$(document).ready(function(){
    $.get('http://.../admin/ReleaseNotes/FY13/UpcomingChanges.txt', function(contents) {
          $("#contentArea").val(contents);
    },'text');
 });

You are trying to request a document on a different domain to the one the request is being made from. 您正在尝试在与请求源不同的域上请求文档。 Same Origin Policy will stop this request completing. 相同来源策略将停止此请求的完成。 There are ways to circumvent this policy though. 尽管有一些方法可以规避此政策。 You can find information in this answer: Ways to circumvent the same-origin policy 您可以在以下答案中找到信息: 规避同源政策的方法

You could also try the following tutorial which will show you how to do a cross domain ajax request with YQL and jQuery. 您也可以尝试以下教程,该教程将向您展示如何使用YQL和jQuery进行跨域ajax请求。

http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-cross-domain-ajax-request-with-yql-and-jquery/ http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-cross-domain-ajax-request-with-yql-and-jquery/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM