admin管理员组文章数量:1292054
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.
- is it possbile to use dataType
text
to do so? - do I need to do any changes on the server side?
ajax call:
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;
}
});
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.
Update 2
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).
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.
- is it possbile to use dataType
text
to do so? - do I need to do any changes on the server side?
ajax call:
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;
}
});
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.
Update 2
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).
-
2
The only type of cross domain call you can do (without a server side proxy) is a
jsonp
call.text
will not work. I'm not sure I understand the SCP part correctly. Can you please elaborate on that? – Mrchief Commented Aug 26, 2011 at 13:55 - @Mrchief : please see update 1 – Radek Commented Aug 28, 2011 at 23:59
- @Malvolio: Melodrama aside, what is wrong? @William Niu` reiterates my thoughts (take a thorough look at the very first line of his answer). He mentions CORS additionally, which is why his is an answer and mine a ment. – Mrchief Commented Aug 30, 2011 at 17:11
- @Mrchief -- what is wrong? You write "The only type of cross domain call you can do (without a server side proxy) is a jsonp call". That is not so. CORS is also a solution (a superior one, in my humble but wholly accurate opinion) and does not require a server-side proxy. The only advantage to JSONP is that it works in Jurassic browsers, so if you need to support the Amish or Colonial Williamsburg or something... – Michael Lorton Commented Aug 31, 2011 at 12:39
-
@Malvolio: It's not wholly accurate. CORS doesn't work in Opera and IE < 8. It has partial support in IE > 8 and uses a different implementation altogether (
XDomainRequest
). Just because your customers didn't plain, do not think that everything is perfect about CORS. And believe it or not, a significant portion of the world still uses Jurassic browsers. Facts aside, the point is, you'd normally mention these type of things in a full fledged answer and not in ment. – Mrchief Commented Aug 31, 2011 at 18:04
4 Answers
Reset to default 3To do cross domain requests, your options are fairly limited. As @Mrchief mentioned, you could do server side proxy and jsonp.
Another option is Cross-Origin Resource Sharing (CORS), a W3C working draft. Quoting from this blog post:
The basic idea behind CORS is to use custom HTTP headers to allow both the browser and the server to know enough about each other to determine if the request or response should succeed or fail.
For a simple request, one that uses either GET or POST with no custom headers and whose body is text/plain, the request is sent with an extra header called Origin. The Origin header contains the origin (protocol, domain name, and port) of the requesting page so that the server can easily determine whether or not it should serve a response.
You can find some live examples on this site.
You will need to make changes to the server side, to accept the CORS requests. Since you have control over the server, this shouldn't be a problem. Another downside with CORS is that, it might not be patible with older browsers. So, if some of your essential audiences use inpatible browsers, the server side proxy may actually be a better option for you.
I just want to offer an alternative.
I am not too sure regarding your network setup, but if you have access to the DNS, maybe it would be easiest if you just give your servers some arbitrary subdomain of the same domain. Something like www.foo.
for the webfront and firebird.private.foo.
for the firebird server. This way, it bees cross subdomain instead of cross domain. Then somewhere in your JavaScript on both pages,
document.domain = "foo.";
This gentleman achieved this solution here.
You have the following options with you
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>
}
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.
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./coupons.txt'))
@play = req.body
you can find more details about the same here.
Hope this helps.
Another idea is to use you web server as a proxy. You will need to consider the security implications for this route.
本文标签: javascriptHow to do cross domain ajax in jQuery with dataType 39text39Stack Overflow
版权声明:本文标题:javascript - How to do cross domain ajax in jQuery with dataType 'text'? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741545063a2384544.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论