zoukankan      html  css  js  c++  java
  • 解决JS跨域访问解决《一》

    前些天做前端登录跳到后端去,发现ajax提交不成功。发现自己没有考虑JS跨域问题。

    对于这个问题,我的解决思路是:

    iframe一个后台的页面,嵌入在前端页面上。

    这样实际上提交信息就不存在跨域问题了。

    提交后我们要对页面进行处理,不能还在iframe里面,后来我又做了几个测试。

    demo如下:

    这是iframe页面

    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <meta name="Generator" content="EditPlus®">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <title>iframe</title>
     </head>
     <body>
      <h1>>>>>this is a page to test iframe</h1>
      <iframe src="iframe_test.html">
      </iframe>
     </body>
    </html>
    

    iframe页面负责嵌套一个页面

    这是iframe_test页面,被iframe页面嵌套的页面

    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <meta name="Generator" content="EditPlus®">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <title>iframe_test</title>
      <script type="text/javascript">
      <!--
    	function redirect(){
    		//window.open('iframe_test_1.html','newwindow','height=700,width=800,top=20,left=100,toolbar=yes,menubar=yes,scrollbars=no, resizable=yes,location=yes, status=yes')
              //这里是用于新建一个页面出来 parent.location.href ="iframe_test_1.html"
              //这个意思就是父级页面跳到iframe_test_1.html
    } //--> </script> 
    </head>
    <body> <button onclick ="redirect()" title ="for testting page iframe">testIframe</button> </body>
    </html>

    其中有一个按钮,来控制做跳转。

    这是iframe_test_1

    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <meta name="Generator" content="EditPlus®">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <title>iframe_test_1</title>
     </head>
     <body>
      <h1>>>>>this is a page by click button</h1>
    
     </body>
    </html>
    

    用来跳转的页面

    积累知识,分享知识,学习知识。
  • 相关阅读:
    JavaScript 格式化数字
    浅析C#中单点登录的原理和使用
    从银行转账失败到分布式事务:总结与思考
    计算机网络资料
    阿里巴巴Java开发规约插件p3c详细教程及使用感受
    程序员如何打造属于自己的云笔记服务
    sql server2016里面的json功能
    mac pro 开启三只滑动选中文本
    技术网站
    idea gradle项目导入
  • 原文地址:https://www.cnblogs.com/bin-pureLife/p/3726983.html
Copyright © 2011-2022 走看看