Introduction to the method of dynamically creating a script tag to achieve Cross-domain resource access

Source: Internet
Author: User
Tags script tag

  This article is mainly on the dynamic creation of the script tag to achieve Cross-domain resource access methods are introduced, the need for friends can come to the reference, I hope to be helpful to everyone

Login.html   Code is as follows: <script>   function Request (Id,url) {     oscript = document.getelement Byid (ID);      var head = document.getElementsByTagName ("Head"). Item (0);      if (oscript) {        Head.removechild (oscript);      }   &NB Sp  oscript = document.createelement ("script");      oscript.setattribute ("src", url);      oscript.setattribute ("id", id);      oscript.setattribute ("type", "Text/javascript");      oscript.setattribute ("language", "JavaScript");      head.appendchild (oscript);      return Oscript; }       function userlogin () {    var Username=document.getelementbyid (' name '). Value;   &NB Sp var Password=document.getelementbyid (' password '). value;      //alert (username+ "-" +password);    var url= ' Http://127.0.0.1:8080/EasyCMS/login. Jsp?name= ' +encodeuri (username) + ' &password= ' +encodeuri (password) + ' &s= ' + (new Date ()). GetTime ();    //alert ("url=" +url);     var login=request ("Loginscript", url); }   function Myloginstate (state) {        alert ("RET:" +state);       if (state==0)    {  alert ("Login succeeded");   &nbsp}    else    {&N Bsp       Alert ("Landing failure");   &NBSP}  }   </script> <body> user name: <input name= "name" id= "name" type= "text"/> Password: <i Nput name= "password" id= "password" type= "password"/> <input name= "" value= "Login" type= "button" onclick= " Userlogin (); "/> </body>     login.jsp    code is as follows: <%@ page language=" java "import=" Java.util.* "pageencoding=" UTF-8 "%> <% String name=request.getparameter (" name "); String password=request.getparameter ("password"); if (name.equals ("admin") && password.equals ("admin")) { requeSt.getsession (). setattribute ("admin", "admin");  %>  myloginstate ("0");   <%} else { %>   myloginstate ("1");   <%  }%>  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.