如何通过ajax调用导航到跨域网页?

时间:2022-10-18 09:18:41

The requirement of my application is to navigate to a cross domain page upon logging out. As probably CORS is not set(error: no Access-Control-Allow-Origin header is present) in the cross domain app, hence response.sendRedirect(url) is not working from JAVA side. Now, realizing this cross domain barrier I did some research in UI side, explored many posts in internet and tried the following to navigate to a cross domain page from UI but with no avail. With Angularjs- $http.jsonp('https://www.google.co.in/');

我的应用程序的要求是在注销时导航到跨域页面。由于可能没有在跨域应用程序中设置CORS(错误:没有Access-Control-Allow-Origin标头),因此response.sendRedirect(url)无法从JAVA端运行。现在,实现这个跨域障碍我在UI方面进行了一些研究,在互联网上探索了很多帖子,并尝试以下从UI导航到跨域页面,但没有用。使用Angularjs- $ http.jsonp('https://www.google.co.in/');

With JQuery by including jquery.ajax-cross-origin.min.js-

使用JQuery包含jquery.ajax-cross-origin.min.js-

$.ajax({crossOrigin: true,url: 'https://www.google.co.in/'});

In both cases it is giving error: SyntaxError: expected expression, got '<'. It looks like it is not expecting '<>' tags, but I am expecting it not to return any response (JSON or XML) but to redirect me to some other domain page (ex: https://www.google.co.in/). Can anybody help me resolving this by giving me an workable code which navigates me to a cross domain page (say: https://www.google.co.in/).

在这两种情况下都会出错:SyntaxError:expected expression,得到'<'。看起来它并不期待'<>'标签,但我希望它不会返回任何响应(JSON或XML),而是将我重定向到其他域页(例如:https://www.google.co。在/)。任何人都可以通过向我提供一个可行的代码帮助我解决这个问题,该代码可以将我导航到跨域页面(例如:https://www.google.co.in/)。

2 个解决方案

#1


5  

instead of $.ajax({crossOrigin: true,url: 'https://www.google.co.in/'}); you have to use window.location.href='https://www.google.co.in/'

而不是$ .ajax({crossOrigin:true,url:'https://www.google.co.in/'});你必须使用window.location.href ='https://www.google.co.in/'

window.location.assign('url')
window.location='url'
window.location.href='url'

all of these will work for you

所有这些都适合你

#2


0  

I tested with my below code it is working:

我用下面的代码测试它正在工作:

<script>
$.ajax({
    type:"POST",
    url: 'a.php?id=1',
    success:function(d){    
    if(d){
        window.location.href="http://www.google.com";

    }

    }

});
</script>

#1


5  

instead of $.ajax({crossOrigin: true,url: 'https://www.google.co.in/'}); you have to use window.location.href='https://www.google.co.in/'

而不是$ .ajax({crossOrigin:true,url:'https://www.google.co.in/'});你必须使用window.location.href ='https://www.google.co.in/'

window.location.assign('url')
window.location='url'
window.location.href='url'

all of these will work for you

所有这些都适合你

#2


0  

I tested with my below code it is working:

我用下面的代码测试它正在工作:

<script>
$.ajax({
    type:"POST",
    url: 'a.php?id=1',
    success:function(d){    
    if(d){
        window.location.href="http://www.google.com";

    }

    }

});
</script>