如何做jQuery的跨域AJAX由于数据类型“文本”? [英] How to do cross domain ajax in jQuery with dataType 'text'?

查看:96
本文介绍了如何做jQuery的跨域AJAX由于数据类型“文本”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我javacript功能,我把这称为AJAX。它工作正常,但只有当我访问从火鸟服务器的网页。我有我的相同的code测试服务器。阿贾克斯要求下载一些文件,但只有火鸟服务器的IP寄存器与我们的客户能够SCP的存在。我需要的,如果我从测试服务器访问PHP文件做同样的。所有的服务器都在里面内联网。

In my javacript function I call this ajax. It works fine but only when I access the web page from firebird server. I have the same code on my testing server. The ajax asks to download some files but only firebird server has its ip registers with our clients to be able to scp there. I need to do the same if I access the php files from testing server. All the servers are inside intranet.

  • 是possbile使用的dataType 文本这样做?
  • 在做我需要做的服务器端什么变化?
  • is it possbile to use dataType text to do so?
  • do I need to do any changes on the server side?

Ajax调用:

url = "https://firebird"+path+"/tools.php?";    

jQuery.ajax({
    type: 'get',
    dataType: 'text',
    url: url,
    data: {database: database_name, what: 'download', files: files, t: Math.random() },
    success: function(data, textStatus){
        document.getElementById("downloading").innerHTML+=data;
    }
});

更新1

我的小Web应用程序还原数据库,这样我可以做我的测试它们。现在我想改善它,所以我可以连接到我们的客户和下载特定的备份。我们的客户只允许火鸟服务器连接到他们的网络。但是,我有我自己的服务器专用于测试。所以每次我要下载我需要连接火鸟的数据库。我的web应用程序,并与所有的备份文件夹的源被安装到两台服务器上的相同位置火鸟测试 。现在我的解决方案(下载)的作品,但只能从火鸟。我的工作基本上只有测试服务器虽然。

Update 1

My little web application restores databases so I can do my testing on them. Now I want to enhance it so I can connect to our customers and download a particular backup. Our customer allowed only firebird server to connect to their networks. But I have my own server dedicated to testing. So every time I want to download a database I need to connect firebird. The source of my web application and the folder with all backups are mounted into the same location on both servers firebird and testing. Right now my solution (for downloading) works but only from firebird. I work basically only testing server though.

我提出两个Ajax调用。一种是纯jQuery的调用(我想我可以申请任何解决这一个),另一种是由jsTree Ajax调用。我创建新问题为那一个。我在我看来,我要去@ ZZZZ的选项B)。

I make two ajax calls. One is pure jQuery call (I guess I can apply any solution to this one) and the other one is ajax call from jsTree. I created new question for that one. I seems to me that I have to go for @zzzz's option b).

推荐答案

您有您以下选项

a)您使用JSONP类型的数据类型,但这需要在服务器端更改的数据回传为JSON,而不是为txt ..这种变化可能很简单,比如

a) You use jsonp type as your datatype but this involves making changes on the server side to pass the data back as json and not as txt.. this change might be as simple as

{
  "text":<your current text json encoded> 
}

和你的JS端,你用这个作为response.text;说了这么多,如果你得到了textis你从SM其他域的文件,我不知道它是多么容易为你改变code。

and on your js side you use this as response.text; Having said that if you are getting the textis for you file from sm other domain I am not sure how easy it is for you to change the code.

二)另一种选择是你写你的服务器即你的域内的处理程序/终点,这将使一个HTTP请求到第三域获取文件,您将文件发送回客户端,并有效地现在你的客户会谈到您的域只和你有过的一切控制。因为大多数yoyr问题是基于Ruby下面是一个例子:

b) The other option is you write a handler/end point on your server i.e within your domain that will make an HTTP request to this third domain gets the file and you send the file back to your client and effectively now your client talks to your domain only and you have control over everything. as most of yoyr questions are based on ruby here is an example:

req = Net::HTTP.get_response(URI.parse('http://www.domain.com/coupons.txt'))

@play = req.body

您可以找到相同的详情这里

希望这有助于。

这篇关于如何做jQuery的跨域AJAX由于数据类型“文本”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆