• 解决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>
    

    用来跳转的页面

    积累知识,分享知识,学习知识。
  • 相关阅读:
    随便说说辞职后
    用Excel的VBA实现文本匹配与替换
    [转]为什么你做不到呢?
    [转]女生,你为什么不沉住气奋斗?
    写在互联网分析的前面
    回归白领的生活
    NSSortDescriptor:对NSDictionary的NSArray进行排序
    本团队推荐:大神开发的仿原神风格ue5开发MMOARPG核心战斗系统
    UE4外包团队:UE4开发元宇宙项目 UE5开发元宇宙或最佳?
    元宇宙外包团队:Unity开发元宇宙应用,在元宇宙里里Unity扮演什么角色?
  • 原文地址:https://www.cnblogs.com/bin-pureLife/p/3726983.html
Copyright © 2020-2023  润新知